Ticket #1169: lives_ok.patch

File lives_ok.patch, 4.7 KB (added by bubaflub, 5 years ago)
  • runtime/parrot/include/test_more.pir

    diff --git runtime/parrot/include/test_more.pir runtime/parrot/include/test_more.pir
    index 318828b..3afbf74 100644
     
    2020    .local pmc exports, curr_namespace, test_namespace 
    2121    curr_namespace = get_namespace 
    2222    test_namespace = get_root_namespace [ 'parrot'; 'Test'; 'More' ] 
    23     exports = split ' ', 'plan diag ok nok is is_deeply like substring isa_ok skip isnt todo throws_like throws_substring' 
     23    exports = split ' ', 'plan diag ok nok is is_deeply like substring isa_ok skip isnt todo throws_like lives_ok throws_substring' 
    2424 
    2525    test_namespace.'export_to'(curr_namespace, exports) 
    2626 
  • runtime/parrot/library/Test/More.pir

    diff --git runtime/parrot/library/Test/More.pir runtime/parrot/library/Test/More.pir
    index de4b7f9..7bde336 100644
     
    1313    .local pmc exports, curr_namespace, test_namespace 
    1414    curr_namespace = get_namespace 
    1515    test_namespace = get_namespace [ 'Test'; 'More' ] 
    16     exports        = split ' ', 'plan diag ok nok is is_deeply like isa_ok skip isnt todo throws_like' 
     16    exports        = split ' ', 'plan diag ok nok is is_deeply like isa_ok skip isnt todo throws_like lives_ok' 
    1717 
    1818    test_namespace.'export_to'(curr_namespace, exports) 
    1919 
     
    838838    .return( equal ) 
    839839.end 
    840840 
     841=item C<lives_ok( codestring, description )> 
     842 
     843Takes PIR code in C<codestring> and an optional message in C<description>. 
     844Passes a test if the PIR does not throw any exception. 
     845 
     846=cut 
     847 
     848.sub lives_ok 
     849    .param string target 
     850    .param string description :optional 
     851 
     852    .local pmc test 
     853    get_hll_global test, [ 'Test'; 'More' ], '_test' 
     854 
     855    .local pmc comp 
     856    .local pmc compfun 
     857    .local pmc compiler 
     858    compiler = compreg 'PIR' 
     859 
     860    .local pmc eh 
     861    eh = new 'ExceptionHandler' 
     862    set_addr eh, handler            # set handler label for exceptions 
     863    push_eh eh 
     864 
     865    compfun = compiler(target) 
     866    compfun()                       # eval the target code 
     867 
     868    pop_eh 
     869 
     870    # if it doesn't throw an exception pass  
     871    test.'ok'( 1, description ) 
     872 
     873    goto done 
     874 
     875  handler: 
     876    .local pmc ex 
     877    .local string error_msg 
     878    .local string diagnostic 
     879 
     880    .get_results (ex) 
     881    pop_eh 
     882    error_msg = ex 
     883    test.'ok'( 0, description ) 
     884    test.'diag'(error_msg) 
     885 
     886  done: 
     887 
     888.end 
     889 
    841890=item C<throws_like( codestring, pattern, description )> 
    842891 
    843892Takes PIR code in C<codestring> and a PGE pattern to match in C<pattern>, as 
  • t/library/test_more.t

    diff --git t/library/test_more.t t/library/test_more.t
    index d511233..a5ea0a8 100644
     
    1515    .local pmc exports, curr_namespace, test_namespace 
    1616    curr_namespace = get_namespace 
    1717    test_namespace = get_namespace [ 'Test'; 'More' ] 
    18     exports = split " ", "ok nok is diag like skip todo is_deeply isa_ok isnt throws_like" 
     18    exports = split " ", "ok nok is diag like skip todo is_deeply isa_ok isnt throws_like lives_ok" 
    1919    test_namespace.'export_to'(curr_namespace, exports) 
    2020 
    2121    test_namespace = get_namespace [ 'Test'; 'Builder'; 'Tester' ] 
     
    3333    test_like() 
    3434    test_is_deeply() 
    3535    test_diagnostics() 
     36    test_lives_ok() 
    3637    test_throws_like() 
    3738    test_isa_ok() 
    3839 
    3940    test.'finish'() 
    4041.end 
    4142 
     43.sub test_lives_ok 
     44 
     45    test_pass( 'lives_ok passes when there is no error' ) 
     46    lives_ok( <<'CODE', 'lives_ok passes when there is no error' ) 
     47.sub main 
     48    $I0 = 42 
     49.end 
     50CODE 
     51    test_test( 'lives_ok passes when there is no error' ) 
     52 
     53    test_fail( 'lives_ok fails when there is an error') 
     54    lives_ok( <<'CODE', 'lives_ok fails when there is an error') 
     55.sub main 
     56    die 'I did it for the lulz' 
     57.end 
     58CODE 
     59    test_diag( 'I did it for the lulz' ) 
     60    test_test( 'lives_ok fails when there is an error' ) 
     61 
     62    test_pass( 'lives_ok passes when there is no error (with diagnostic message)' ) 
     63    lives_ok( <<'CODE', 'lives_ok passes when there is no error (with diagnostic message)' ) 
     64.sub main 
     65    $I0 = 42 
     66.end 
     67CODE 
     68    test_diag( '' ) 
     69    test_test( 'lives_ok passes when there is no error (with diagnostic message)' ) 
     70 
     71    test_fail( 'lives_ok fails when there is an error (with diagnostic message)' ) 
     72    lives_ok( <<'CODE', 'lives_ok fails when there is an error (with diagnostic message)' ) 
     73.sub main 
     74    die 'I did it for the lulz' 
     75.end 
     76CODE 
     77    test_diag( 'I did it for the lulz' ) 
     78    test_test( 'lives_ok fails when there is an error' ) 
     79.end 
     80 
    4281.sub test_throws_like 
    4382 
    4483    test_fail('throws_like fails when there is no error')