integration tests: Replace lazy_static with SyncLazy

This commit is contained in:
Philipp Hansch 2020-10-06 08:20:18 +02:00
parent 4b459596a9
commit 9b4ceee593
No known key found for this signature in database
GPG Key ID: 188FE733728652B1
3 changed files with 21 additions and 24 deletions

View File

@ -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 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);
}
};
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
}
};
}
dir.push(env!("PROFILE"));
dir
}
});
#[must_use]
pub fn is_rustc_test_suite() -> bool {

View File

@ -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;

View File

@ -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() {