Skip to content

Commit 9b4ceee

Browse files
committed
integration tests: Replace lazy_static with SyncLazy
1 parent 4b45959 commit 9b4ceee

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

tests/cargo/mod.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
use lazy_static::lazy_static;
21
use std::env;
2+
use std::lazy::SyncLazy;
33
use std::path::PathBuf;
44

5-
lazy_static! {
6-
pub static ref CARGO_TARGET_DIR: PathBuf = {
7-
match env::var_os("CARGO_TARGET_DIR") {
8-
Some(v) => v.into(),
9-
None => env::current_dir().unwrap().join("target"),
10-
}
11-
};
12-
pub static ref TARGET_LIB: PathBuf = {
13-
if let Some(path) = option_env!("TARGET_LIBS") {
14-
path.into()
15-
} else {
16-
let mut dir = CARGO_TARGET_DIR.clone();
17-
if let Some(target) = env::var_os("CARGO_BUILD_TARGET") {
18-
dir.push(target);
19-
}
20-
dir.push(env!("PROFILE"));
21-
dir
5+
pub static CARGO_TARGET_DIR: SyncLazy<PathBuf> = SyncLazy::new(|| match env::var_os("CARGO_TARGET_DIR") {
6+
Some(v) => v.into(),
7+
None => env::current_dir().unwrap().join("target"),
8+
});
9+
10+
pub static TARGET_LIB: SyncLazy<PathBuf> = SyncLazy::new(|| {
11+
if let Some(path) = option_env!("TARGET_LIBS") {
12+
path.into()
13+
} else {
14+
let mut dir = CARGO_TARGET_DIR.clone();
15+
if let Some(target) = env::var_os("CARGO_BUILD_TARGET") {
16+
dir.push(target);
2217
}
23-
};
24-
}
18+
dir.push(env!("PROFILE"));
19+
dir
20+
}
21+
});
2522

2623
#[must_use]
2724
pub fn is_rustc_test_suite() -> bool {

tests/compile-test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(test)] // compiletest_rs requires this attribute
2+
#![feature(once_cell)]
23

34
use compiletest_rs as compiletest;
45
use compiletest_rs::common::Mode as TestMode;

tests/dogfood.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
// Dogfood cannot run on Windows
22
#![cfg(not(windows))]
3+
#![feature(once_cell)]
34

4-
use lazy_static::lazy_static;
5+
use std::lazy::SyncLazy;
56
use std::path::PathBuf;
67
use std::process::Command;
78

89
mod cargo;
910

10-
lazy_static! {
11-
static ref CLIPPY_PATH: PathBuf = cargo::TARGET_LIB.join("cargo-clippy");
12-
}
11+
static CLIPPY_PATH: SyncLazy<PathBuf> = SyncLazy::new(|| cargo::TARGET_LIB.join("cargo-clippy"));
1312

1413
#[test]
1514
fn dogfood_clippy() {

0 commit comments

Comments
 (0)