|
| 1 | +const INJECTION_COMMIT: &'static str = "f8fd4624474a68bd26694eff3536b9f3a127b2d3"; |
| 2 | +const INJECTION_LOWER_BOUND: &'static str = "2020-02-06"; |
| 3 | +const INJECTION_UPPER_BOUND: &'static str = "2020-02-08"; |
| 4 | + |
| 5 | +const INJECTION_POINT: InjectionPoint = InjectionPoint { |
| 6 | + date: YearMonthDay(2020, 02, 07), |
| 7 | + associated_sha: INJECTION_COMMIT, |
| 8 | +}; |
| 9 | + |
| 10 | +mod cli { |
| 11 | + pub(crate) mod meta_build; |
| 12 | +} |
| 13 | + |
| 14 | +pub(crate) use self::cli::meta_build; |
| 15 | + |
| 16 | +mod common { |
| 17 | + pub(crate) mod command_invocation; |
| 18 | + pub(crate) mod make_a_crate; |
| 19 | + pub(crate) mod which_temp; |
| 20 | +} |
| 21 | + |
| 22 | +pub(crate) use self::common::command_invocation; |
| 23 | +pub(crate) use self::common::make_a_crate; |
| 24 | +pub(crate) use self::common::which_temp; |
| 25 | + |
| 26 | +use self::meta_build::{DeltaKind, InjectionPoint, Test, YearMonthDay}; |
| 27 | +use self::which_temp::{WhichTempDir, WhichTempDirectory}; |
| 28 | + |
| 29 | +// These tests pass `--preserve` and `--access=github` because that is the best |
| 30 | +// way to try to ensure that the tests complete as quickly as possible. |
| 31 | + |
| 32 | +pub const BASIC_TEST: Test = Test { |
| 33 | + crate_name: "cbr_test_cli_basic", |
| 34 | + cli_params: &["--preserve", "--access=github", |
| 35 | + "--start", INJECTION_LOWER_BOUND, "--end", INJECTION_UPPER_BOUND], |
| 36 | + delta_date: INJECTION_POINT, |
| 37 | + delta_kind: DeltaKind::Err, |
| 38 | +}; |
| 39 | + |
| 40 | +pub const FIXED_TEST: Test = Test { |
| 41 | + crate_name: "cbr_test_cli_fixed", |
| 42 | + cli_params: &["--regress=success", |
| 43 | + "--preserve", "--access=github", |
| 44 | + "--start", INJECTION_LOWER_BOUND, "--end", INJECTION_UPPER_BOUND], |
| 45 | + delta_date: INJECTION_POINT, |
| 46 | + delta_kind: DeltaKind::Fix, |
| 47 | +}; |
| 48 | + |
| 49 | +// Ordinarily, I would put both of these tests into separate `#[test]` methods. |
| 50 | +// However, if you do that, then `cargo test` will run them in parallel, and you |
| 51 | +// end up with `cargo-bisect-rustc` racing to install the toolchains it |
| 52 | +// downloads. |
| 53 | +// |
| 54 | +// (It is arguably a bug that we do not gracefully handle this situation.) |
| 55 | +// |
| 56 | +// In any case, the simplest fix for the test infrastructure is to ensure that |
| 57 | +// no tests overlap in the range of dates they search for a regression. |
| 58 | +#[test] |
| 59 | +fn cli_test() -> Result<(), failure::Error> { |
| 60 | + test_cli_core::<WhichTempDir>(&BASIC_TEST)?; |
| 61 | + test_cli_core::<WhichTempDir>(&FIXED_TEST)?; |
| 62 | + Ok(()) |
| 63 | +} |
| 64 | + |
| 65 | +fn test_cli_core<WhichTemp>(test: &meta_build::Test) -> Result<(), failure::Error> |
| 66 | +where WhichTemp: WhichTempDirectory |
| 67 | +{ |
| 68 | + let root = WhichTemp::root()?; |
| 69 | + let tmp_dir = WhichTemp::target(&root); |
| 70 | + let dir = tmp_dir.join(test.crate_name); |
| 71 | + |
| 72 | + let dir_builder = WhichTemp::dir_builder(); |
| 73 | + meta_build::make_crate_files(&dir_builder, &dir, test)?; |
| 74 | + |
| 75 | + let mut cmd = command_invocation::Context { |
| 76 | + cli_params: test.cli_params, |
| 77 | + dir: dir.as_path(), |
| 78 | + }; |
| 79 | + |
| 80 | + let command_invocation::Output { status: _, stderr, stdout } = cmd.run()?; |
| 81 | + |
| 82 | + println!("Command output stdout for {}: \n```\n{}\n```", test.crate_name, stdout); |
| 83 | + println!("Command output stderr for {}: \n```\n{}\n```", test.crate_name, stderr); |
| 84 | + |
| 85 | + // The most basic check: does the output actually tell us about the |
| 86 | + // "regressing" commit. |
| 87 | + let needle = format!("Regression in {}", test.expected_sha()); |
| 88 | + // println!("searching for {:?} in stdout: {:?} stderr: {:?}", needle, stdout, stderr); |
| 89 | + assert!(stderr.contains(&needle)); |
| 90 | + |
| 91 | + Ok(()) |
| 92 | +} |
0 commit comments