From d595689ccfc7a8943a527c39684c49c6907a5bf7 Mon Sep 17 00:00:00 2001 From: chaos Date: Thu, 7 Nov 2024 09:10:34 +0000 Subject: [PATCH] update --- runTests.sh | 7 +++---- tool/testLib.jq | 31 +++++++++---------------------- tool/tests.jq | 14 +++++--------- 3 files changed, 17 insertions(+), 35 deletions(-) diff --git a/runTests.sh b/runTests.sh index d67269a..18846d9 100755 --- a/runTests.sh +++ b/runTests.sh @@ -3,8 +3,7 @@ set -eu SCRIPT_DIR="$(cd -- "$(dirname -- "$0")" && pwd)" -cd "$SCRIPT_DIR/tool" +cd "$SCRIPT_DIR" -jq -n -r -L . "include \"testLib\"; testLibMain" -jq -n -r -L . "include \"tests\"; testsMain" \ - --slurpfile "file:testdata/tests_export.json" testdata/tests_export.json \ No newline at end of file +${JQ:-jq} -n -r -L tool -L . "include \"testLib\"; testLibMain" +${JQ:-jq} -n -r -L tool -L . "include \"tests\"; testsMain" \ No newline at end of file diff --git a/tool/testLib.jq b/tool/testLib.jq index 7d928e1..897f8d4 100644 --- a/tool/testLib.jq +++ b/tool/testLib.jq @@ -3,11 +3,10 @@ def printTestResult: if .passed then "Test \"\(.name)\" Passed" else - (if (.loc != null) then " at \(.loc.file):\(.loc.line)" else "" end) as $fileLocation | - "Test \"\(.name)\"\($fileLocation) Failed\nReason: \(.reason)\nOutput: \(.output | tojson)" + "Test \"\(.name)\" Failed\nReason: \(.reason)\nOutput: \(.output | tojson)" end; -def runTest($loc; $name; testExpr; checkResult; $expectError): +def runTest($name; testExpr; checkResult; $expectError): try ( (null | testExpr) as $output | if $expectError then @@ -15,23 +14,20 @@ def runTest($loc; $name; testExpr; checkResult; $expectError): $name, passed: false, reason: "Expected error but no error was raised", - $output, - $loc + $output } elif ($output | checkResult) then { $name, passed: true, - $output, - $loc + $output } else { $name, passed: false, reason: "Result was different from expected", - $output, - $loc + $output } end ) catch ( @@ -41,23 +37,20 @@ def runTest($loc; $name; testExpr; checkResult; $expectError): $name, passed: false, reason: "Error caught when no error was expected", - output: $error, - $loc + output: $error } elif ($expectError and ($error | checkResult)) then { $name, passed: true, - output: $error, - $loc + output: $error } elif ($expectError and ($error | checkResult | not)) then { $name, passed: false, reason: "Expected error but received different error", - output: $error, - $loc + output: $error } else error("unknown error") @@ -78,42 +71,36 @@ def expectFailed($result): $result | expectFailed; def testTests: expectPassed(runTest( - $__loc__; "passing test"; true; . == true; false )) | expectPassed(runTest( - $__loc__; "error expected and equal"; error("error"); . == "error"; true )) | expectFailed(runTest( - $__loc__; "failing test"; true; . == false; false )) | expectFailed(runTest( - $__loc__; "error expected but no error"; null; . == null; true )) | expectFailed(runTest( - $__loc__; "error not expected"; error("error"); . == null; false )) | expectFailed(runTest( - $__loc__; "error different"; error("error"); . == "different error"; @@ -122,6 +109,6 @@ def testTests: def testLibMain: testTests | - empty | + "Tests Passed\n" | halt_error(0); diff --git a/tool/tests.jq b/tool/tests.jq index 887415a..6cadd79 100644 --- a/tool/tests.jq +++ b/tool/tests.jq @@ -1,17 +1,13 @@ -#import "./testdata/tests_export" as $exportData; +import "./testdata/tests_export" as $exportData; include "journalUtils"; include "testLib"; def testsMain: - $ARGS.named["file:testdata/tests_export.json"][0] as $exportData | - expectPassed(runTest( - $__loc__; "invalid input to experienceByTitle"; ( - $exportData.experiences | - experienceByTitle("Test") + {} | experienceByTitle("Test") ); - . == "error"; - false - )); + . == "experienceByTitle takes a array of experiences as input"; + true + )) | "Tests Passed\n" | halt_error(0);