Skip to content

Commit 31b65be

Browse files
committed
Fix test on Windows
1 parent 0ef074d commit 31b65be

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

crates/oak_ide/tests/integration/find_references.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ use oak_scan::DbExt;
2020
use url::Url;
2121

2222
fn file_url(name: &str) -> Url {
23-
Url::parse(&format!("file:///project/R/{name}")).unwrap()
23+
// `Url::to_file_path` on Windows requires a drive-letter prefix, so
24+
// synthesize one for tests. Linux is happy with rootless paths.
25+
if cfg!(windows) {
26+
Url::parse(&format!("file:///C:/project/R/{name}")).unwrap()
27+
} else {
28+
Url::parse(&format!("file:///project/R/{name}")).unwrap()
29+
}
2430
}
2531

2632
fn upsert(db: &mut OakDatabase, name: &str, contents: &str) -> File {

crates/oak_ide/tests/integration/rename.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ use salsa::Setter;
1818
use url::Url;
1919

2020
fn file_url(name: &str) -> Url {
21-
Url::parse(&format!("file:///project/R/{name}")).unwrap()
21+
// `Url::to_file_path` on Windows requires a drive-letter prefix, so
22+
// synthesize one for tests. Linux is happy with rootless paths.
23+
if cfg!(windows) {
24+
Url::parse(&format!("file:///C:/project/R/{name}")).unwrap()
25+
} else {
26+
Url::parse(&format!("file:///project/R/{name}")).unwrap()
27+
}
2228
}
2329

2430
fn upsert(db: &mut OakDatabase, name: &str, contents: &str) -> File {
@@ -269,7 +275,12 @@ fn place_in_workspace_scripts(db: &mut OakDatabase, files: Vec<File>) {
269275
// real scan guarantees: `File::root` resolves an unpackaged file to the
270276
// root whose scan reached it, and `source()` anchoring reads that root's
271277
// path.
272-
let url = FilePath::from_url(&Url::parse("file:///project/R/").unwrap());
278+
let raw = if cfg!(windows) {
279+
"file:///C:/project/R/"
280+
} else {
281+
"file:///project/R/"
282+
};
283+
let url = FilePath::from_url(&Url::parse(raw).unwrap());
273284
let root = Root::new(db, url, RootKind::Workspace, files, vec![]);
274285
db.workspace_roots().set_roots(db).to(vec![root]);
275286
}

0 commit comments

Comments
 (0)