Unit testing: Difference between revisions
(Advocate for more unit testing) |
No edit summary |
||
Line 3: | Line 3: | ||
Demonstrate any support for Unit testing built into the language implementation. |
Demonstrate any support for Unit testing built into the language implementation. |
||
See https://en.wikipedia.org/wiki/Unit_testing for more information. |
See https://en.wikipedia.org/wiki/Unit_testing and [[Test a function]] for more information. |
||
Clearly state whether this support is internal, or external to the interpreter or compiler used. |
Clearly state whether this support is internal, or external to the interpreter or compiler used. |
Revision as of 21:16, 17 February 2019
Demonstrate any support for Unit testing built into the language implementation.
See https://en.wikipedia.org/wiki/Unit_testing and Test a function for more information.
Clearly state whether this support is internal, or external to the interpreter or compiler used.
Jsish
Jsish supports an internal -u command line option to run unit tests, as part of the base implementation. These tests can include trial inputs and expected outputs in special comment blocks within a source file. Other command line options determine the level of verbosity and logging used when running tests. Being inside comment sections, unit tests do not affect the normal operation of a script (besides the negligible time taken for the interpreter to read in and skip over the comment sections). When in -u test-mode, source lines starting and ending with semi-colons ; are echoed using a special output format that also evaluates the enclosed expression and captures the result.
<lang javascript>/* A+B in Jsish */ var line = console.input(); var nums = line.match(/^\s*([+-]?[0-9]+)\s+([+-]?[0-9]+)\s*/); if (nums) {
var A = Number(nums[1]); var B = Number(nums[2]); if (A <= 1000 && A >= -1000 && B <= 1000 && B >= -1000) { printf("%d\n", A + B); } else { puts("error: A and B both need to be in range -1000 thru 1000 inclusive"); }
} else {
puts("error: A+B requires two numbers separated by space");
}
/*
!INPUTSTART!
a b 1234 123 -1000 +1000 123 -234
!INPUTEND!
- /
/*
!EXPECTSTART!
error: A+B requires two numbers separated by space error: A and B both need to be in range -1000 thru 1000 inclusive 0 -111
!EXEPECTEND!
- /</lang>
- Output:
prompt$ jsish -u A+B.jsi [PASS] A+B.jsi prompt$ jsish A+B.jsi 123 -234 -111