Skip to content

Commit

Permalink
integration tests: Replace lazy_static with SyncLazy
Browse files Browse the repository at this point in the history
  • Loading branch information
phansch committed Oct 6, 2020
1 parent 4b45959 commit 9b4ceee
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
37 changes: 17 additions & 20 deletions tests/cargo/mod.rs
@@ -1,27 +1,24 @@
use lazy_static::lazy_static;
use std::env;
use std::lazy::SyncLazy;
use std::path::PathBuf;

lazy_static! {
pub static ref CARGO_TARGET_DIR: PathBuf = {
match env::var_os("CARGO_TARGET_DIR") {
Some(v) => v.into(),
None => env::current_dir().unwrap().join("target"),
}
};
pub static ref TARGET_LIB: PathBuf = {
if let Some(path) = option_env!("TARGET_LIBS") {
path.into()
} else {
let mut dir = CARGO_TARGET_DIR.clone();
if let Some(target) = env::var_os("CARGO_BUILD_TARGET") {
dir.push(target);
}
dir.push(env!("PROFILE"));
dir
pub static CARGO_TARGET_DIR: SyncLazy<PathBuf> = SyncLazy::new(|| match env::var_os("CARGO_TARGET_DIR") {
Some(v) => v.into(),
None => env::current_dir().unwrap().join("target"),
});

pub static TARGET_LIB: SyncLazy<PathBuf> = SyncLazy::new(|| {
if let Some(path) = option_env!("TARGET_LIBS") {
path.into()
} else {
let mut dir = CARGO_TARGET_DIR.clone();
if let Some(target) = env::var_os("CARGO_BUILD_TARGET") {
dir.push(target);
}
};
}
dir.push(env!("PROFILE"));
dir
}
});

#[must_use]
pub fn is_rustc_test_suite() -> bool {
Expand Down
1 change: 1 addition & 0 deletions tests/compile-test.rs
@@ -1,4 +1,5 @@
#![feature(test)] // compiletest_rs requires this attribute
#![feature(once_cell)]

use compiletest_rs as compiletest;
use compiletest_rs::common::Mode as TestMode;
Expand Down
7 changes: 3 additions & 4 deletions tests/dogfood.rs
@@ -1,15 +1,14 @@
// Dogfood cannot run on Windows
#![cfg(not(windows))]
#![feature(once_cell)]

use lazy_static::lazy_static;
use std::lazy::SyncLazy;
use std::path::PathBuf;
use std::process::Command;

mod cargo;

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

#[test]
fn dogfood_clippy() {
Expand Down

0 comments on commit 9b4ceee

Please sign in to comment.