diff --git runtime/parrot/include/test_more.pir runtime/parrot/include/test_more.pir
index 3afbf74..e368535 100644
|
|
|
20 | 20 | .local pmc exports, curr_namespace, test_namespace |
21 | 21 | curr_namespace = get_namespace |
22 | 22 | 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' |
24 | 24 | |
25 | 25 | test_namespace.'export_to'(curr_namespace, exports) |
26 | 26 | |
diff --git runtime/parrot/library/Test/More.pir runtime/parrot/library/Test/More.pir
index fa4d271..c34026f 100644
|
|
|
13 | 13 | .local pmc exports, curr_namespace, test_namespace |
14 | 14 | curr_namespace = get_namespace |
15 | 15 | 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' |
17 | 17 | |
18 | 18 | test_namespace.'export_to'(curr_namespace, exports) |
19 | 19 | |
… |
… |
|
838 | 838 | .return( equal ) |
839 | 839 | .end |
840 | 840 | |
| 841 | =item C<dies_ok( codestring, description )> |
| 842 | |
| 843 | Takes PIR code in C<codestring> and an optional message in C<description>. |
| 844 | Passes 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 | |
841 | 890 | =item C<lives_ok( codestring, description )> |
842 | 891 | |
843 | 892 | Takes PIR code in C<codestring> and an optional message in C<description>. |
diff --git t/library/test_more.t t/library/test_more.t
index 00bc89a..b4fa044 100644
|
|
|
15 | 15 | .local pmc exports, curr_namespace, test_namespace |
16 | 16 | curr_namespace = get_namespace |
17 | 17 | 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" |
19 | 19 | test_namespace.'export_to'(curr_namespace, exports) |
20 | 20 | |
21 | 21 | test_namespace = get_namespace [ 'Test'; 'Builder'; 'Tester' ] |
22 | 22 | exports = split " ", "plan test_out test_diag test_fail test_pass test_test" |
23 | 23 | test_namespace.'export_to'(curr_namespace, exports) |
24 | 24 | |
25 | | plan( 98 ) |
| 25 | plan( 102 ) |
26 | 26 | |
27 | 27 | test_skip() |
28 | 28 | test_todo() |
… |
… |
|
34 | 34 | test_is_deeply() |
35 | 35 | test_diagnostics() |
36 | 36 | test_lives_ok() |
| 37 | test_dies_ok() |
37 | 38 | test_throws_like() |
38 | 39 | test_isa_ok() |
39 | 40 | |
40 | 41 | test.'finish'() |
41 | 42 | .end |
42 | 43 | |
| 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 |
| 50 | CODE |
| 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 |
| 58 | CODE |
| 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 |
| 67 | CODE |
| 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 |
| 76 | CODE |
| 77 | test_diag( 'no error thrown' ) |
| 78 | test_test( 'dies_ok fails when there is no error with diagnostic message' ) |
| 79 | |
| 80 | .end |
| 81 | |
43 | 82 | .sub test_lives_ok |
44 | 83 | |
45 | 84 | test_pass( 'lives_ok passes when there is no error' ) |