Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-02-23 15:45:54 -0500
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-02-23 15:45:54 -0500
commit2f7ad95a2c62a1a81b8498ab970d512d398eb837 (patch)
tree45965a621a94b632e9f7d3344ca3a20131363bd4 /progtest/src
parent7475b5b928751fcc0c536d183d49ee8891436a00 (diff)
downloadtame-2f7ad95a2c62a1a81b8498ab970d512d398eb837.tar.gz
tame-2f7ad95a2c62a1a81b8498ab970d512d398eb837.tar.bz2
tame-2f7ad95a2c62a1a81b8498ab970d512d398eb837.zip
TestRunner: Recognize error as failurev2.10.1
Diffstat (limited to 'progtest/src')
-rw-r--r--progtest/src/TestRunner.js44
1 files changed, 37 insertions, 7 deletions
diff --git a/progtest/src/TestRunner.js b/progtest/src/TestRunner.js
index b7685dc..abbdda1 100644
--- a/progtest/src/TestRunner.js
+++ b/progtest/src/TestRunner.js
@@ -134,7 +134,7 @@ module.exports = Class( 'TestRunner',
'private _runTest'( { description: desc, data, expect }, test_i, total )
{
// no input map---#rate uses params directly
- const result = this._program.rater( data ).vars;
+ const result = this._tryRun( data );
const cmp = Object.keys( expect ).map(
field => [
@@ -143,12 +143,18 @@ module.exports = Class( 'TestRunner',
]
);
- const failures = cmp.filter( ( [ , ok ] ) => !ok )
- .map( ( [ field ] ) => ( {
- field: field,
- expect: expect[ field ],
- result: result[ field ],
- } ) );
+ const failures = ( result instanceof Error )
+ ? [ {
+ field: "error",
+ expect: "",
+ result: result.message,
+ } ]
+ : cmp.filter( ( [ , ok ] ) => !ok )
+ .map( ( [ field ] ) => ( {
+ field: field,
+ expect: expect[ field ],
+ result: result[ field ],
+ } ) );
const succeeded = cmp.length - failures.length;
@@ -168,6 +174,30 @@ module.exports = Class( 'TestRunner',
/**
+ * Attempt test case, returning error on failure
+ *
+ * If an error is thrown (e.g. terminating classification), it will be
+ * returned in place of the results.
+ *
+ * @param {Object} data input data
+ *
+ * @return {Object|Error} result or error
+ */
+ 'private _tryRun'( data )
+ {
+ // no input map---#rate uses params directly
+ try
+ {
+ return this._program.rater( data ).vars;
+ }
+ catch( e )
+ {
+ return e;
+ }
+ },
+
+
+ /**
* Recursively compare values (scalar, array)
*
* @param {number|Array<number>} x first value