Skip to content

Commit

Permalink
Drop once_cell (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Sep 28, 2022
1 parent 660f2b0 commit a2796d2
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 75 deletions.
25 changes: 12 additions & 13 deletions .github/workflows/tests.yml
Expand Up @@ -31,16 +31,15 @@ jobs:
- name: Test
run: make test

## our dependencies no longer support this
# build-old-stable:
# name: Check on 1.51.0
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - uses: actions-rs/toolchain@v1
# with:
# toolchain: 1.51.0
# profile: minimal
# override: true
# - name: Check
# run: cargo check --no-default-features
build-old-stable:
name: Check on 1.51.0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.51.0
profile: minimal
override: true
- name: Check
run: cargo check --no-default-features
6 changes: 3 additions & 3 deletions Cargo.toml
Expand Up @@ -5,7 +5,7 @@ license = "Apache-2.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
description = "A snapshot testing library for Rust"
edition = "2018"
rust-version = "1.56.0"
rust-version = "1.51.0"
homepage = "https://insta.rs/"
repository = "https://github.com/mitsuhiko/insta"
keywords = ["snapshot", "testing", "jest", "approval"]
Expand Down Expand Up @@ -45,19 +45,19 @@ yaml = ["serde"]

[dependencies]
dep_csv = { package = "csv", version = "1.1.4", optional = true }
console = { version = "0.15.1", optional = true, default-features = false }
console = { version = "0.15.2", optional = true, default-features = false }
pest = { version = "2.1.3", optional = true }
pest_derive = { version = "2.1.0", optional = true }
dep_ron = { package = "ron", version = "0.7.1", optional = true }
dep_toml = { package = "toml", version = "0.5.7", optional = true }
globset = { version = "0.4.6", optional = true }
walkdir = { version = "2.3.1", optional = true }
similar = { version = "2.1.0", features = ["inline"] }
once_cell = "1.9.0"
regex = { version = "1.6.0", default-features = false, optional = true, features = ["std", "unicode"] }
yaml-rust = "0.4.5"
serde = { version = "1.0.117", optional = true }
linked-hash-map = "0.5.6"
lazy_static = "1.4.0"

[dev-dependencies]
serde = { version = "1.0.117", features = ["derive"] }
Expand Down
8 changes: 4 additions & 4 deletions cargo-insta/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/env.rs
Expand Up @@ -4,12 +4,11 @@ use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::{env, fs};

use once_cell::sync::Lazy;

use crate::utils::is_ci;

static WORKSPACES: Lazy<Mutex<BTreeMap<String, Arc<PathBuf>>>> =
Lazy::new(|| Mutex::new(BTreeMap::new()));
lazy_static::lazy_static! {
static ref WORKSPACES: Mutex<BTreeMap<String, Arc<PathBuf>>> = Mutex::new(BTreeMap::new());
}

/// How snapshots are supposed to be updated
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down
35 changes: 19 additions & 16 deletions src/glob.rs
Expand Up @@ -3,7 +3,6 @@ use std::path::Path;
use std::sync::Mutex;

use globset::{GlobBuilder, GlobMatcher};
use once_cell::sync::Lazy;
use walkdir::WalkDir;

use crate::settings::Settings;
Expand All @@ -17,22 +16,26 @@ pub(crate) struct GlobCollector {

// the glob stack holds failure count + an indication if cargo insta review
// should be run.
pub(crate) static GLOB_STACK: Lazy<Mutex<Vec<GlobCollector>>> = Lazy::new(Mutex::default);
lazy_static::lazy_static! {
pub(crate) static ref GLOB_STACK: Mutex<Vec<GlobCollector>> = Mutex::default();
}

static GLOB_FILTER: Lazy<Vec<GlobMatcher>> = Lazy::new(|| {
env::var("INSTA_GLOB_FILTER")
.unwrap_or_default()
.split(';')
.filter(|x| !x.is_empty())
.filter_map(|filter| {
GlobBuilder::new(filter)
.case_insensitive(true)
.build()
.ok()
.map(|x| x.compile_matcher())
})
.collect()
});
lazy_static::lazy_static! {
static ref GLOB_FILTER: Vec<GlobMatcher> = {
env::var("INSTA_GLOB_FILTER")
.unwrap_or_default()
.split(';')
.filter(|x| !x.is_empty())
.filter_map(|filter| {
GlobBuilder::new(filter)
.case_insensitive(true)
.build()
.ok()
.map(|x| x.compile_matcher())
})
.collect()
};
}

pub fn glob_exec<F: FnMut(&Path)>(base: &Path, pattern: &str, mut f: F) {
let glob = GlobBuilder::new(pattern)
Expand Down
12 changes: 6 additions & 6 deletions src/runtime.rs
Expand Up @@ -7,8 +7,6 @@ use std::path::{Path, PathBuf};
use std::str;
use std::sync::{Arc, Mutex};

use once_cell::sync::Lazy;

use crate::env::{
force_pass, force_update_snapshots, get_cargo_workspace, get_output_behavior,
get_snapshot_update_behavior, memoize_snapshot_file, OutputBehavior, SnapshotUpdate,
Expand All @@ -18,10 +16,12 @@ use crate::settings::Settings;
use crate::snapshot::{MetaData, PendingInlineSnapshot, Snapshot, SnapshotContents};
use crate::utils::{path_to_storage, style};

static TEST_NAME_COUNTERS: Lazy<Mutex<BTreeMap<String, usize>>> =
Lazy::new(|| Mutex::new(BTreeMap::new()));
static TEST_NAME_CLASH_DETECTION: Lazy<Mutex<BTreeMap<String, bool>>> =
Lazy::new(|| Mutex::new(BTreeMap::new()));
lazy_static::lazy_static! {
static ref TEST_NAME_COUNTERS: Mutex<BTreeMap<String, usize>> =
Mutex::new(BTreeMap::new());
static ref TEST_NAME_CLASH_DETECTION: Mutex<BTreeMap<String, bool>> =
Mutex::new(BTreeMap::new());
}

// This macro is basically eprintln but without being captured and
// hidden by the test runner.
Expand Down
39 changes: 20 additions & 19 deletions src/settings.rs
Expand Up @@ -6,7 +6,6 @@ use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};

use once_cell::sync::Lazy;
#[cfg(feature = "serde")]
use serde::{de::value::Error as ValueError, Serialize};

Expand All @@ -18,24 +17,26 @@ use crate::filters::Filters;
#[cfg(feature = "redactions")]
use crate::redaction::{dynamic_redaction, sorted_redaction, ContentPath, Redaction, Selector};

static DEFAULT_SETTINGS: Lazy<Arc<ActualSettings>> = Lazy::new(|| {
Arc::new(ActualSettings {
sort_maps: false,
snapshot_path: "snapshots".into(),
snapshot_suffix: "".into(),
input_file: None,
description: None,
info: None,
omit_expression: false,
prepend_module_to_snapshot: true,
#[cfg(feature = "redactions")]
redactions: Redactions::default(),
#[cfg(feature = "filters")]
filters: Filters::default(),
#[cfg(feature = "glob")]
allow_empty_glob: false,
})
});
lazy_static::lazy_static! {
static ref DEFAULT_SETTINGS: Arc<ActualSettings> = {
Arc::new(ActualSettings {
sort_maps: false,
snapshot_path: "snapshots".into(),
snapshot_suffix: "".into(),
input_file: None,
description: None,
info: None,
omit_expression: false,
prepend_module_to_snapshot: true,
#[cfg(feature = "redactions")]
redactions: Redactions::default(),
#[cfg(feature = "filters")]
filters: Filters::default(),
#[cfg(feature = "glob")]
allow_empty_glob: false,
})
};
}
thread_local!(static CURRENT_SETTINGS: RefCell<Settings> = RefCell::new(Settings::new()));

/// Represents stored redactions.
Expand Down
20 changes: 10 additions & 10 deletions src/snapshot.rs
Expand Up @@ -8,16 +8,16 @@ use std::time::{SystemTime, UNIX_EPOCH};

use crate::content::{self, json, yaml, Content};

use once_cell::sync::Lazy;

static RUN_ID: Lazy<String> = Lazy::new(|| {
if let Ok(run_id) = env::var("NEXTEST_RUN_ID") {
run_id
} else {
let d = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
format!("{}-{}", d.as_secs(), d.subsec_nanos())
}
});
lazy_static::lazy_static! {
static ref RUN_ID: String = {
if let Ok(run_id) = env::var("NEXTEST_RUN_ID") {
run_id
} else {
let d = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
format!("{}-{}", d.as_secs(), d.subsec_nanos())
}
};
}

#[derive(Debug)]
pub struct PendingInlineSnapshot {
Expand Down

0 comments on commit a2796d2

Please sign in to comment.