summaryrefslogtreecommitdiff
path: root/tests/src
diff options
context:
space:
mode:
authorLeedehai <18319900+Leedehai@users.noreply.github.com>2023-12-06 05:02:27 -0500
committerGitHub <noreply@github.com>2023-12-06 11:02:27 +0100
commit9a62b21a25cd9a56090e0bf1afecfa3888d810d8 (patch)
treed33c12ae6ba81bd7236ad2c00b4726e14ab91875 /tests/src
parentd1835b418f1bc261d6f81f6f31ffa3f137b4908c (diff)
Let test.rs --exact also accept file path of a typ file (#2817)
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/tests.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/tests/src/tests.rs b/tests/src/tests.rs
index d7722ce6..465c5b6f 100644
--- a/tests/src/tests.rs
+++ b/tests/src/tests.rs
@@ -6,7 +6,7 @@ use std::ffi::OsStr;
use std::fmt::{self, Display, Formatter, Write as _};
use std::io::{self, IsTerminal, Write};
use std::ops::Range;
-use std::path::{Path, PathBuf};
+use std::path::{Path, PathBuf, MAIN_SEPARATOR_STR};
use std::{env, fs};
use clap::Parser;
@@ -31,6 +31,7 @@ use typst::{Library, World, WorldExt};
use unscanny::Scanner;
use walkdir::WalkDir;
+// These directories are all relative to the tests/ directory.
const TYP_DIR: &str = "typ";
const REF_DIR: &str = "ref";
const PNG_DIR: &str = "png";
@@ -71,14 +72,19 @@ struct PrintConfig {
}
impl Args {
- fn matches(&self, path: &Path) -> bool {
- if self.exact {
- let name = path.file_name().unwrap().to_string_lossy();
- self.filter.iter().any(|v| v == &name)
- } else {
- let path = path.to_string_lossy();
- self.filter.is_empty() || self.filter.iter().any(|v| path.contains(v))
+ fn matches(&self, canonicalized_path: &Path) -> bool {
+ let path = canonicalized_path.to_string_lossy();
+ if !self.exact {
+ return self.filter.is_empty()
+ || self.filter.iter().any(|v| path.contains(v));
}
+
+ self.filter.iter().any(|v| match path.strip_suffix(v) {
+ None => false,
+ Some(residual) => {
+ residual.is_empty() || residual.ends_with(MAIN_SEPARATOR_STR)
+ }
+ })
}
}
@@ -89,7 +95,7 @@ fn main() {
let world = TestWorld::new(args.print);
println!("Running tests...");
- let results = WalkDir::new("typ")
+ let results = WalkDir::new(TYP_DIR)
.into_iter()
.par_bridge()
.filter_map(|entry| {
@@ -102,12 +108,12 @@ fn main() {
return None;
}
- let src_path = entry.into_path();
+ let src_path = entry.into_path(); // Relative to TYP_DIR.
if src_path.extension() != Some(OsStr::new("typ")) {
return None;
}
- if args.matches(&src_path) {
+ if args.matches(&src_path.canonicalize().unwrap()) {
Some(src_path)
} else {
None