Skip to content

Commit

Permalink
[tw][image] Allow empty --list-tests arg
Browse files Browse the repository at this point in the history
Summary:
For pyunit test `--list-tests` optionally takes in a argument e.g.

```
 (b17a9f4ae) ~/fbsource/fbcode $ /data/users/jcahill/fbsource/buck-out/v2/gen/fbcode/24c04fc3eb9063ab/testinfra/playground/sudotest/__python-sudo-test-sudo-test-inner__/python-sudo-test-sudo-test-inner.par --list-tests
test_playground (testinfra.playground.sudotest.SudoTest.ExampleSudoTest)
test_playground2 (testinfra.playground.sudotest.SudoTest.ExampleSudoTest)
test_root_access (testinfra.playground.sudotest.SudoTest.ExampleSudoTest)
```

Update `image_test` to allow pyunit tests to allow for this

Test Plan: CI

Reviewed By: sergeyfd

Differential Revision: D51360121

fbshipit-source-id: 54b297bc2005a6bb8e00df2119834ecb7ec31820
  • Loading branch information
jamiecahill authored and facebook-github-bot committed Nov 28, 2023
1 parent aafb3f2 commit 0e63689
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions antlir/antlir2/testing/image_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub enum Test {
test_cmd: Vec<OsString>,
},
Pyunit {
#[clap(long)]
list_tests: Option<PathBuf>,
#[clap(long, default_value=None,default_missing_value=Some(""),num_args=0..=1)]
list_tests: Option<String>,
#[clap(long)]
output: Option<PathBuf>,
#[clap(long)]
Expand Down Expand Up @@ -71,11 +71,14 @@ impl Test {
} => {
let mut paths = HashSet::new();
if let Some(p) = list_tests {
paths.insert(
p.parent()
.expect("output file always has parent")
.to_owned(),
);
if !p.is_empty() {
paths.insert(
PathBuf::from(p)
.parent()
.expect("output file always has parent")
.to_owned(),
);
}
}
if let Some(p) = output {
paths.insert(
Expand Down Expand Up @@ -111,7 +114,9 @@ impl Test {
} => {
if let Some(list) = list_tests {
test_cmd.push("--list-tests".into());
test_cmd.push(list.into());
if !list.is_empty() {
test_cmd.push(list.into());
}
}
if let Some(out) = output {
test_cmd.push("--output".into());
Expand Down Expand Up @@ -258,6 +263,11 @@ mod test {
arg.test.into_inner_cmd(),
vec!["whatever", "--list-tests", "/a/here"]
);

let arg = TestArgs::parse_from(["test", "pyunit", "whatever", "--list-tests"]);
assert!(arg.test.is_list_tests());
assert!(arg.test.output_dirs().is_empty());
assert_eq!(arg.test.into_inner_cmd(), vec!["whatever", "--list-tests"]);
}

#[test]
Expand Down

0 comments on commit 0e63689

Please sign in to comment.