perlmojolicioustap

How to check that last test is failed?


I test my code via Test2::V0

is $result, 'value', 'Test OK';

Can I check that last test is failed?

In mojolicious, for example, there is ->or(sub{ ... })

Does Test2::V0 have something similar?


Solution

  • Test functions have return values -- a true value or a false value depending on the outcome of the test -- which can be captured or checked.

    if (! is $result, 'value', 'Test Ok') {
        warn "Test 42 failed. Skip test 43\n";
    }
    
    is $result, 'value', 'Test Ok'
        or warn "Test 42 failed. Skip test 43\n";
    
    $z1 = is $result1, 'value1';
    $z2 = is $result2, 'value2';
    $z3 = is $result3, 'value3';
    if (!!$z1 + !!$z2 + !!$z3 >= 2) {
        print "At least two of the previous three tests passed!\n";
    }