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

Commit ebd520d

Browse files
committed
Use tempdir instead of target/ to generate src/test/mod.rs fixtures
1 parent 56e4380 commit ebd520d

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ rustc-workspace-hack = "1.0.0"
5151

5252
[dev-dependencies]
5353
difference = "2"
54+
tempfile = "3"
5455

5556
[build-dependencies]
5657
rustc_tools_util = { git = "https://github.com/rust-lang/rust-clippy", rev = "a3c77f6ad1c1c185e561e9cd7fdec7db569169d1" }

src/test/harness.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use std::collections::HashMap;
1414
use std::env;
1515
use std::fs::File;
16-
use std::io::{BufRead, BufReader};
16+
use std::io::{self, BufRead, BufReader};
1717
use std::path::{Path, PathBuf};
1818
use std::sync::atomic::{AtomicUsize, Ordering};
1919
use std::sync::{Arc, Mutex};
@@ -26,9 +26,7 @@ use lazy_static::lazy_static;
2626
use rls_analysis::{AnalysisHost, Target};
2727
use rls_vfs::Vfs;
2828
use serde_json;
29-
30-
#[path = "../../tests/support/project_builder.rs"]
31-
mod project_builder;
29+
use walkdir::WalkDir;
3230

3331
lazy_static! {
3432
static ref COUNTER: AtomicUsize = AtomicUsize::new(0);
@@ -50,9 +48,8 @@ impl Environment {
5048
}
5149

5250
let fixture_dir = FIXTURES_DIR.join(fixture_dir.as_ref());
53-
let project = project_builder::ProjectBuilder::try_from_fixture(fixture_dir)
54-
.unwrap()
55-
.build();
51+
let scratchpad_dir = build_scratchpad_from_fixture(fixture_dir)
52+
.expect("Can't copy fixture files to scratchpad");
5653

5754
let target_dir = env::var("CARGO_TARGET_DIR")
5855
.map(|s| Path::new(&s).to_owned())
@@ -66,7 +63,7 @@ impl Environment {
6663
config.target_dir = Inferrable::Specified(Some(working_dir.clone()));
6764
config.unstable_features = true;
6865

69-
let cache = Cache::new(project.root().to_owned());
66+
let cache = Cache::new(scratchpad_dir);
7067

7168
Self {
7269
config: Some(config),
@@ -114,6 +111,32 @@ impl Drop for Environment {
114111
}
115112
}
116113

114+
pub fn build_scratchpad_from_fixture(fixture_dir: impl AsRef<Path>) -> io::Result<PathBuf> {
115+
let fixture_dir = fixture_dir.as_ref();
116+
117+
let dirname = fixture_dir.file_name()
118+
.ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "No filename"))?;
119+
120+
// FIXME: For now persist the path; ideally we should clean up after every test
121+
let genroot = tempfile::tempdir()?.into_path().join(dirname);
122+
// Recursively copy read-only fixture files to freshly generated scratchpad
123+
for entry in WalkDir::new(fixture_dir).into_iter() {
124+
let entry = entry?;
125+
let src = entry.path();
126+
127+
let relative = src.strip_prefix(fixture_dir).unwrap();
128+
let dst = genroot.join(relative);
129+
130+
if std::fs::metadata(src)?.is_dir() {
131+
std::fs::create_dir(dst)?;
132+
} else {
133+
std::fs::copy(src, dst)?;
134+
}
135+
}
136+
137+
Ok(genroot)
138+
}
139+
117140
struct MockMsgReader {
118141
messages: Vec<String>,
119142
cur: AtomicUsize,

0 commit comments

Comments
 (0)