Skip to content

Commit

Permalink
Test warning about unexpected nextest exit codes
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Feb 7, 2025
1 parent 4f24b13 commit 9ed0731
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use crate::Result;

// Allowed nextest codes (those will be considered a mutation caught / ignored without a warning)
const NEXTEST_ALLOWED_CODES: &[i32] = &[
NextestExitCode::TEST_RUN_FAILED,
NextestExitCode::NO_TESTS_RUN,
NextestExitCode::TEST_RUN_FAILED,
NextestExitCode::BUILD_FAILED,
];

Expand Down
59 changes: 58 additions & 1 deletion tests/nextest.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright 2024 Martin Pool
// Copyright 2024-2025 Martin Pool

//! Integration tests for cargo mutants calling nextest.
use std::fs::{create_dir, write};

use predicates::prelude::*;
use tempfile::TempDir;

mod util;
use util::{copy_of_testdata, run};
Expand All @@ -27,3 +30,57 @@ fn test_with_nextest_on_small_tree() {
String::from_utf8_lossy(&assert.get_output().stdout)
);
}

#[test]
fn unexpected_nextest_error_code_causes_a_warning() {
let temp = TempDir::new().unwrap();
let path = temp.path();
write(
path.join("Cargo.toml"),
r#"[package]
name = "cargo-mutants-test"
version = "0.1.0"
publish = false
"#,
)
.unwrap();
create_dir(path.join("src")).unwrap();
write(
path.join("src/main.rs"),
r#"fn main() {
println!("{}", 1 + 2);
}"#,
)
.unwrap();
create_dir(path.join(".config")).unwrap();
write(
path.join(".config/nextest.toml"),
r#"nextest-version = { required = "9999.0.0" }"#,
)
.unwrap();

let assert = run()
.args([
"mutants",
"--test-tool",
"nextest",
"-vV",
"--no-shuffle",
"-Ldebug",
])
.arg("-d")
.arg(temp.path())
.assert()
.stderr(predicates::str::contains(
"nextest process exited with unexpected code (allowed: [4, 100, 101]) code=92",
))
.code(4); // CLEAN_TESTS_FAILED
println!(
"stdout:\n{}",
String::from_utf8_lossy(&assert.get_output().stdout)
);
println!(
"stderr:\n{}",
String::from_utf8_lossy(&assert.get_output().stderr)
);
}

0 comments on commit 9ed0731

Please sign in to comment.