Skip to content

Commit

Permalink
--output creates the containing directory
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Sep 11, 2022
1 parent 25ab2b6 commit ae6bfe1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- New: `missed.txt`, `caught.txt`, `timeout.txt` and `unviable.txt` files are written in to the output directory to make results easier to review later.

- New: `--output` creates the containing directory if it does not exist.

- Internal: Switched from Argh to Clap for command-line parsing. There may be some small changes in CLI behavior and help formatting.

## 1.0.0
Expand Down
6 changes: 6 additions & 0 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,18 @@ pub struct OutputDir {
impl OutputDir {
/// Create a new `mutants.out` output directory, within the given directory.
///
/// If `in_dir` does not exist, it's created too, so that users can name a new directory
/// with `--output`.
///
/// If the directory already exists, it's rotated to `mutants.out.old`. If that directory
/// exists, it's deleted.
///
/// If the directory already exists and `lock.json` exists and is locked, this waits for
/// the lock to be released. The returned `OutputDir` holds a lock for its lifetime.
pub fn new(in_dir: &Utf8Path) -> Result<OutputDir> {
if !in_dir.exists() {
fs::create_dir(&in_dir).context("create output parent directory {in_dir:?}")?;
}
let output_dir = in_dir.join(OUTDIR_NAME);
if output_dir.exists() {
LockFile::acquire_lock(output_dir.as_ref())?;
Expand Down
41 changes: 18 additions & 23 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,17 +757,21 @@ fn small_well_tested_mutants_with_cargo_arg_release() {
}

#[test]
/// The `--output` directory creates the named directory if necessary, and then
/// creates `mutants.out` within it. `mutants.out` is not created in the
/// source directory in this case.
fn output_option() {
let tmp_src_dir = copy_of_testdata("factorial");
let output_tmpdir = TempDir::new().unwrap();
let output_parent = output_tmpdir.path().join("output_parent");
assert!(
!tmp_src_dir.path().join("mutants.out").exists(),
"mutants.out should not be in a clean copy of the test data"
);
run_assert_cmd()
.arg("mutants")
.arg("--output")
.arg(&output_tmpdir.path())
.arg(&output_parent)
.args(["--check", "--no-times"])
.arg("-d")
.arg(&tmp_src_dir.path())
Expand All @@ -777,28 +781,19 @@ fn output_option() {
!tmp_src_dir.path().join("mutants.out").exists(),
"mutants.out should not be in the source directory after --output was given"
);
assert!(
output_tmpdir.path().join("mutants.out").exists(),
"mutants.out is in --output directory"
);
assert!(
output_tmpdir
.path()
.join("mutants.out/mutants.json")
.is_file(),
"mutants.out/mutants.json is in --output directory"
);
assert!(
output_tmpdir
.path()
.join("mutants.out/outcomes.json")
.is_file(),
"mutants.out/outcomes.json is in --output directory"
);
assert!(
output_tmpdir.path().join("mutants.out/debug.log").is_file(),
"mutants.out/debug.log is in --output directory"
);
let mutants_out = output_parent.join("mutants.out");
assert!(mutants_out.exists(), "mutants.out is in --output directory");
for name in [
"mutants.json",
"debug.log",
"outcomes.json",
"missed.txt",
"caught.txt",
"timeout.txt",
"unviable.txt",
] {
assert!(mutants_out.join(name).is_file(), "{name} is in mutants.out",);
}
}

#[test]
Expand Down

0 comments on commit ae6bfe1

Please sign in to comment.