forked from microsoft/qsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharness.rs
34 lines (28 loc) · 1.19 KB
/
harness.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use std::{path::PathBuf, sync::Arc};
use expect_test::Expect;
use qsc_project::{FileSystem, Manifest, StdFs};
pub fn check(project_path: &PathBuf, expect: &Expect) {
let mut root_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
root_path.push(PathBuf::from("tests/projects"));
let mut absolute_project_path = root_path.clone();
absolute_project_path.push(project_path);
let manifest = Manifest::load_from_path(absolute_project_path)
.expect("manifest should load")
.expect("manifest should contain descriptor");
let fs = StdFs;
let mut project = fs.load_project(&manifest).expect("project should load");
// remove the prefix absolute path
for (path, _contents) in &mut project.sources {
let new_path = PathBuf::from(path.to_string());
let new_path = new_path
.strip_prefix(&root_path)
.expect("prefix should be present")
.to_string_lossy();
let new_path = new_path.replace(std::path::MAIN_SEPARATOR, "/");
*path = Arc::from(new_path);
}
project.sources.sort();
expect.assert_eq(&format!("{project:#?}"));
}