Ticket #1183: dies_ok.patch

File dies_ok.patch, 4.9 KB (added by bubaflub, 5 years ago)

patch for dies_ok

  • runtime/parrot/include/test_more.pir

    diff --git runtime/parrot/include/test_more.pir runtime/parrot/include/test_more.pir
    index 3afbf74..e368535 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 lives_ok throws_substring' 
     23    exports = split ' ', 'plan diag ok nok is is_deeply like substring isa_ok skip isnt todo throws_like lives_ok dies_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 fa4d271..c34026f 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 lives_ok' 
     16    exports        = split ' ', 'plan diag ok nok is is_deeply like isa_ok skip isnt todo throws_like lives_ok dies_ok' 
    1717 
    1818    test_namespace.'export_to'(curr_namespace, exports) 
    1919 
     
    838838    .return( equal ) 
    839839.end 
    840840 
     841=item C<dies_ok( codestring, description )> 
     842 
     843Takes PIR code in C<codestring> and an optional message in C<description>. 
     844Passes a test if the PIR does throw any exception. 
     845 
     846=cut 
     847 
     848.sub dies_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 fail 
     871    test.'ok'( 0, description ) 
     872    test.'diag'('no error thrown') 
     873 
     874    goto done 
     875 
     876  handler: 
     877    .local pmc ex 
     878    .local string error_msg 
     879    .local string diagnostic 
     880 
     881    .get_results (ex) 
     882    pop_eh 
     883    error_msg = ex 
     884    test.'ok'( 1, description ) 
     885 
     886  done: 
     887 
     888.end 
     889 
    841890=item C<lives_ok( codestring, description )> 
    842891 
    843892Takes PIR code in C<codestring> and an optional message in C<description>. 
  • t/library/test_more.t

    diff --git t/library/test_more.t t/library/test_more.t
    index 00bc89a..b4fa044 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 lives_ok" 
     18    exports = split " ", "ok nok is diag like skip todo is_deeply isa_ok isnt throws_like lives_ok dies_ok" 
    1919    test_namespace.'export_to'(curr_namespace, exports) 
    2020 
    2121    test_namespace = get_namespace [ 'Test'; 'Builder'; 'Tester' ] 
    2222    exports = split " ", "plan test_out test_diag test_fail test_pass test_test" 
    2323    test_namespace.'export_to'(curr_namespace, exports) 
    2424 
    25     plan( 98 ) 
     25    plan( 102 ) 
    2626 
    2727    test_skip() 
    2828    test_todo() 
     
    3434    test_is_deeply() 
    3535    test_diagnostics() 
    3636    test_lives_ok() 
     37    test_dies_ok() 
    3738    test_throws_like() 
    3839    test_isa_ok() 
    3940 
    4041    test.'finish'() 
    4142.end 
    4243 
     44.sub test_dies_ok 
     45    test_pass( 'dies_ok passes when there is an error' ) 
     46    dies_ok( <<'CODE', 'dies_ok passes when there is an error' ) 
     47.sub main 
     48    die 'I did it for the lulz' 
     49.end 
     50CODE 
     51    test_test( 'dies_ok passes when there is an error' ) 
     52 
     53    test_fail( 'dies_ok fails when there is no error' ) 
     54    dies_ok( <<'CODE', 'dies_ok fails when there is no error' ) 
     55.sub main 
     56    $I0 = 42 
     57.end 
     58CODE 
     59    test_diag( 'no error thrown' ) 
     60    test_test( 'dies_ok fails when there is no error' ) 
     61 
     62    test_pass( 'dies_ok passes when there is an error with diagnostic message' ) 
     63    dies_ok( <<'CODE', 'dies_ok passes when there is an error with diagnostic message' ) 
     64.sub main 
     65    die 'I did it for the lulz' 
     66.end 
     67CODE 
     68    test_diag( '' ) 
     69    test_test( 'dies_ok passes when there is an error with diagnostic message' ) 
     70 
     71    test_fail( 'dies_ok fails when there is no error with diagnostic message' ) 
     72    dies_ok( <<'CODE', 'dies_ok fails when there is no error with diagnostic message' ) 
     73.sub main 
     74    $I0 = 42 
     75.end 
     76CODE 
     77    test_diag( 'no error thrown' ) 
     78    test_test( 'dies_ok fails when there is no error with diagnostic message' ) 
     79 
     80.end 
     81 
    4382.sub test_lives_ok 
    4483 
    4584    test_pass( 'lives_ok passes when there is no error' )