Repository: aptos-labs/aptos-core
File: third_party/move/tools/move-unit-test/tests/move_unit_test_testsuite.rs (Rust)

Code before:
    let exp_ext = get_compiler_exp_extension();
    for modifier in TEST_MODIFIER_STRS.iter() {
        let modified_exp_path = path.with_extension(format!("{}.{}", modifier, exp_ext));
        if let (Some(test_config), true) = (
            modify(unit_test_config.clone(), modifier),
            modified_exp_path.exists(),
        ) {
            let buffer = Vec::new();
            let test_plan = test_config.build_test_plan();
            if test_plan.is_none() {
                anyhow::bail!(
                    "No test plan constructed for {:?} with modifier {}",
                    path,
                    modifier
                );
            }

            results.push((
                test_config.run_and_report_unit_tests(
                    test_plan.unwrap(),
                    None,
                    None,
                    buffer,
                    UnitTestFactoryWithCostTable::new(None, None),
                    unit_test_config.fail_fast,
                )?,
                modified_exp_path,
            ))
        }
    }

    // Now run with no modifiers
    let buffer = Vec::new();
    let test_plan = unit_test_config.build_test_plan();
    if test_plan.is_none() {
        anyhow::bail!("No test plan constructed for {:?}", path);
    }

    results.push((
        unit_test_config.run_and_report_unit_tests(
            test_plan.unwrap(),
            None,
            None,
            buffer,
            UnitTestFactoryWithCostTable::new(None, None),
            unit_test_config.fail_fast,
        )?,
        path.with_extension(exp_ext),
    ));

    Ok(results)

Review comment (bug):
Can you please add some tests to showcase fail fast? The tests can be added in this crate. Some cases to consider when adding tests:
1. multiple tests fail, but with fail fast, we stop after the first error
2. multiple tests fail, but without fail fast, all failures are reported
3. some tests are expected to fail with a specific abort. with fail fast, we don't stop (and all tests "pass" with the appropriate failure), because these are all expected errors.



Code after:
    let exp_ext = get_compiler_exp_extension();
    for modifier in TEST_MODIFIER_STRS.iter() {
        let modified_exp_path = path.with_extension(format!("{}.{}", modifier, exp_ext));
        if let (Some(test_config), true) = (
            modify(unit_test_config.clone(), modifier),
            modified_exp_path.exists(),
        ) {
            let buffer = Vec::new();
            let test_plan = test_config.build_test_plan();
            if test_plan.is_none() {
                anyhow::bail!(
                    "No test plan constructed for {:?} with modifier {}",
                    path,
                    modifier
                );
            }

            results.push((
                test_config.run_and_report_unit_tests(
                    test_plan.unwrap(),
                    None,
                    None,
                    buffer,
                    UnitTestFactoryWithCostTable::new(None, None),
                    false,
                    unit_test_config.fail_fast,
                )?,
                modified_exp_path,
            ))
        }
    }

    // Now run with no modifiers
    let buffer = Vec::new();
    let test_plan = unit_test_config.build_test_plan();
    if test_plan.is_none() {
        anyhow::bail!("No test plan constructed for {:?}", path);
    }

    results.push((
        unit_test_config.run_and_report_unit_tests(
            test_plan.unwrap(),
            None,
            None,
            buffer,
            UnitTestFactoryWithCostTable::new(None, None),
            false,
            unit_test_config.fail_fast,
        )?,
        path.with_extension(exp_ext),
    ));