Skip to content

Commit

Permalink
Add support to pass args to test bins
Browse files Browse the repository at this point in the history
  • Loading branch information
mgattozzi committed Jul 31, 2023
1 parent 771f17e commit 40fab82
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions justfile
Expand Up @@ -12,4 +12,7 @@ build:
./target/bootstrap/freight build
test: build
mkdir -p target/test
# Test that we can pass args to the tests
./target/debug/freight test ignored-arg -- --list
# Actually run the tests
./target/debug/freight test
4 changes: 2 additions & 2 deletions src/lib.rs
Expand Up @@ -157,7 +157,7 @@ pub fn build_tests() -> Result<()> {
Ok(())
}

pub fn run_tests() -> Result<()> {
pub fn run_tests(test_args: Vec<String>) -> Result<()> {
for item in root_dir()?
.join("target")
.join("debug")
Expand All @@ -168,7 +168,7 @@ pub fn run_tests() -> Result<()> {
let path = item.path();
let is_test = path.extension().is_none();
if is_test {
Command::new(path).spawn()?.wait()?;
Command::new(path).args(&test_args).spawn()?.wait()?;
}
}
Ok(())
Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Expand Up @@ -10,7 +10,13 @@ fn main() -> Result<(), Box<dyn Error>> {
Some("build") => freight::build()?,
Some("test") => {
freight::build_tests()?;
freight::run_tests()?
loop {
match args.next().as_ref().map(String::as_str) {
Some("--") | None => break,
_ => continue,
}
}
freight::run_tests(args.collect::<Vec<String>>())?
}
Some("help") => println!("{HELP}"),
_ => {
Expand Down

0 comments on commit 40fab82

Please sign in to comment.