Test a function: Difference between revisions

m
→‎{{header|Phix}}: added set_test_abort()
m (→‎{{header|Phix}}: replaced -1/0/1 with the proper named constants)
m (→‎{{header|Phix}}: added set_test_abort())
Line 1,541:
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #000080;font-style:italic;">--set_test_verbosity(TEST_QUIET) -- (default, no output when third call removed)
--set_test_verbosity(TEST_SUMMARY) -- (first and last line only [w or w/o ""])
--set_test_verbosity(TEST_SHOW_FAILED) -- (first and last two lines only)</span>
<span style="color: #7060A8;">set_test_verbosity</span><span style="color: #0000FF;">(</span><span style="color: #004600;">TEST_SHOW_ALL</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (as shown in last two cases below)
--set_test_pauseset_test_abort(TEST_PAUSE_FAILTEST_ABORT) -- abort(pause1) on failure, [default])after showing the summary
--set_test_pauseset_test_abort(TEST_QUIET) -- (disablequietly pausecarry on, failure)the default
--set_test_pauseset_test_abort(TEST_PAUSETEST_CRASH) -- abort immmediately on failure (alwaysw/o pausesummary)</span>
--set_test_pause(TEST_PAUSE_FAIL) -- pause on failure, the default
<span style="color: #7060A8;">set_test_module</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"palindromes"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (optional, w/o first line is omitted)</span>
--set_test_pause(TEST_QUIET) -- disable pause on failure
--set_test_pause(TEST_PAUSE) -- always pause</span>
<span style="color: #7060A8;">set_test_module</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"palindromes"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (optional, w/o first line is omitted)</span>
<span style="color: #7060A8;">test_true</span><span style="color: #0000FF;">(</span><span style="color: #000000;">is_palindrome</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"abba"</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"abba"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">test_true</span><span style="color: #0000FF;">(</span><span style="color: #000000;">is_palindrome</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"abba"</span><span style="color: #0000FF;">))</span> <span style="color: #000080;font-style:italic;">-- (no desc makes success hidden...)
-- (...and failure somewhat laconic)</span>
<span style="color: #7060A8;">test_false</span><span style="color: #0000FF;">(</span><span style="color: #000000;">is_palindrome</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"abc"</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"not abc"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">test_true</span><span style="color: #0000FF;">(</span><span style="color: #000000;">is_palindrome</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"failure"</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"failure"</span><span style="color: #0000FF;">)</span>
Line 1,560 ⟶ 1,564:
<span style="color: #7060A8;">test_summary</span><span style="color: #0000FF;">()</span>
<!--</lang>-->
Note the default behaviour, if set_test_verbosity() is not invoked, is no output and carry on as normal when all tests pass.<br>
Also note that set_test_pause() has no effect under pwa/p2js and the program will always carry on regardless of any failure, <br>
unless set_test_abort() other than TEST_QUIET is in force. You can of course invoke these routines in a platform-dependent <br>
way, for instance pause on the desktop but abort/stop completely in the browser, should that help.
{{out}}
TEST_QUIET with a failing test (no output or pause if no failing tests)<br>
7,813

edits