Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit e2bc57b

Browse files
committed
Simplify fixture dir handling in Environment
1 parent 659eb94 commit e2bc57b

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

src/test/harness.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ mod support;
3232

3333
lazy_static! {
3434
static ref COUNTER: AtomicUsize = AtomicUsize::new(0);
35+
static ref MANIFEST_DIR: &'static Path = Path::new(env!("CARGO_MANIFEST_DIR"));
36+
static ref FIXTURES_DIR: PathBuf = MANIFEST_DIR.join("test_data");
3537
}
3638

3739
crate struct Environment {
@@ -42,23 +44,19 @@ crate struct Environment {
4244

4345
impl Environment {
4446
crate fn generate_from_fixture(fixture_dir: impl AsRef<Path>) -> Self {
45-
let fixture_dir = fixture_dir.as_ref();
46-
4747
let _ = env_logger::try_init();
4848
if env::var("RUSTC").is_err() {
4949
env::set_var("RUSTC", "rustc");
5050
}
5151

52-
let manifest_dir = &Path::new(env!("CARGO_MANIFEST_DIR"));
53-
let fixture_dir = manifest_dir.join("test_data").join(fixture_dir);
54-
52+
let fixture_dir = FIXTURES_DIR.join(fixture_dir.as_ref());
5553
let project = support::ProjectBuilder::try_from_fixture(fixture_dir)
5654
.unwrap()
5755
.build();
5856

5957
let target_dir = env::var("CARGO_TARGET_DIR")
6058
.map(|s| Path::new(&s).to_owned())
61-
.unwrap_or_else(|_| manifest_dir.join("target"));
59+
.unwrap_or_else(|_| MANIFEST_DIR.join("target"));
6260

6361
let working_dir = target_dir
6462
.join("tests")
@@ -83,18 +81,9 @@ impl Environment {
8381
env::set_var("RUSTC", "rustc");
8482
}
8583

86-
// Acquire the current directory, but this is changing when tests are
87-
// running so we need to be sure to access it in a synchronized fashion.
88-
let cur_dir = {
89-
use crate::build::environment::{Environment, EnvironmentLock};
90-
let env = EnvironmentLock::get();
91-
let (guard, _other) = env.lock();
92-
let env = Environment::push_with_lock(&HashMap::new(), None, guard);
93-
match env::var_os("RLS_TEST_WORKSPACE_DIR") {
94-
Some(cur_dir) => cur_dir.into(),
95-
None => env.get_old_cwd().to_path_buf(),
96-
}
97-
};
84+
let cur_dir = env::var_os("RLS_TEST_WORKSPACE_DIR")
85+
.map(PathBuf::from)
86+
.unwrap_or_else(|| MANIFEST_DIR.to_owned());
9887
let project_path = cur_dir.join("test_data").join(project_dir);
9988

10089
let target_dir = env::var("CARGO_TARGET_DIR")

0 commit comments

Comments
 (0)