Skip to content

Commit

Permalink
Merge pull request #12 from xffxff/relative_path
Browse files Browse the repository at this point in the history
use relative paths in diagnostics for test cases
  • Loading branch information
xffxff authored Nov 12, 2023
2 parents e47220a + 7bab1a9 commit 8321278
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lox_tests/diagnostics/error_in_function/output
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Error: expected `;`
╭─[/home/zhoufan/workspace/rust/lox/lox_tests/diagnostics/error_in_function.lox:2:18]
╭─[lox_tests/diagnostics/error_in_function.lox:2:18]
2 │ print "hello"
│ ┬
Expand Down
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,18 @@ impl TestCase {
}
}

// relative path relative to crate root
fn relative_path(path: &Path) -> PathBuf {
let crate_root_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
path.strip_prefix(crate_root_dir).unwrap().to_owned()
}

fn test(self, db: &Database) {
print!("test {} ... ", self.lox.display());
let relative_path = TestCase::relative_path(&self.lox);
let input_file = InputFile::new(
db,
Word::intern(db, self.lox.to_str().unwrap()),
Word::intern(db, relative_path.to_str().unwrap()),
self.text.clone(),
);

Expand Down

0 comments on commit 8321278

Please sign in to comment.