From 5dd5716c69a81f245d1a1e9a3a1c3c1ffd55ec86 Mon Sep 17 00:00:00 2001 From: christian-byrne Date: Fri, 20 Sep 2024 15:14:11 -0700 Subject: [PATCH] Reconfigure GH workflows for new test runner --- .github/workflows/run-sml-tests.yml | 9 +- .github/workflows/run-smlsharp-tests.yml | 2 +- requirements.txt | 1 - test.py | 38 +++--- tests/test_ica5.sml | 154 ----------------------- 5 files changed, 26 insertions(+), 178 deletions(-) delete mode 100644 tests/test_ica5.sml diff --git a/.github/workflows/run-sml-tests.yml b/.github/workflows/run-sml-tests.yml index 426ae33..efc76bf 100644 --- a/.github/workflows/run-sml-tests.yml +++ b/.github/workflows/run-sml-tests.yml @@ -21,8 +21,15 @@ jobs: sudo apt-get update sudo apt-get install smlnj # Install SML/NJ + - name: Install python dependencies + run: | + sudo apt-get install python3 + sudo apt-get install python3-pip + pip3 install --upgrade pip + pip3 install -r requirements.txt + - name: Run SML tests run: | chmod +x test - ./test false + ./test diff --git a/.github/workflows/run-smlsharp-tests.yml b/.github/workflows/run-smlsharp-tests.yml index 4c1bc28..f91ac83 100644 --- a/.github/workflows/run-smlsharp-tests.yml +++ b/.github/workflows/run-smlsharp-tests.yml @@ -30,4 +30,4 @@ jobs: - name: Run SML tests run: | chmod +x test - ./test true + ./test-smlunit diff --git a/requirements.txt b/requirements.txt index b523419..c94be38 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ -argparse rich \ No newline at end of file diff --git a/test.py b/test.py index dd7f734..f220c01 100644 --- a/test.py +++ b/test.py @@ -339,26 +339,22 @@ def run_test(test_path: Path): logging.info(f"Log file location: {str(Path(args.log_file))}") -def write_to_cache(): - try: - with open(args.cache_path, "r") as cache_file: - cache = json.load(cache_file) - except (json.JSONDecodeError, FileNotFoundError): - # Previous error wrote corrupted cache file or first run - clear_cache() - cache = {} - - def write_(test_set: Set[Path], cache_key: str): - cache[cache_key] = str(test_set.pop().resolve()) if test_set else "" - - write_(runtime_error_tests, "runtime_error_tests") - write_(failed_tests, "failed_tests") - write_(passed_tests, "passed_tests") - write_( - runtime_error_tests.union(failed_tests).union(passed_tests), "all_seen_tests" - ) - with open(args.cache_path, "w") as cache_file: - json.dump(cache, cache_file) +try: + with open(args.cache_path, "r") as cache_file: + cache = json.load(cache_file) +except (json.JSONDecodeError, FileNotFoundError): + # Previous error wrote corrupted cache file or first run + clear_cache() + cache = {} +def write_(test_set: Set[Path], cache_key: str): + cache[cache_key] = str(test_set.pop().resolve()) if test_set else "" -write_to_cache() +write_(runtime_error_tests, "runtime_error_tests") +write_(failed_tests, "failed_tests") +write_(passed_tests, "passed_tests") +write_( + runtime_error_tests.union(failed_tests).union(passed_tests), "all_seen_tests" +) +with open(args.cache_path, "w") as cache_file: + json.dump(cache, cache_file) diff --git a/tests/test_ica5.sml b/tests/test_ica5.sml deleted file mode 100644 index e239845..0000000 --- a/tests/test_ica5.sml +++ /dev/null @@ -1,154 +0,0 @@ -(* ICA 5 tests *) - -use "src/ica05/ica5.sml"; -use "tests/utils.sml"; - - -val testCasesLog2 = [ - (log2, 1, 0), (* 2^0 = 1 *) - (log2, 2, 1), (* 2^1 = 2 *) - (log2, 4, 2), (* 2^2 = 4 *) - (log2, 8, 3), (* 2^3 = 8 *) - (log2, 16, 4), (* 2^4 = 16 *) - (log2, 32, 5), (* 2^5 = 32 *) - (log2, 64, 6), (* 2^6 = 64 *) - (log2, 128, 7), (* 2^7 = 128 *) - (log2, 256, 8) (* 2^8 = 256 *) -]; -runTestCasesIntInt(testCasesLog2); - -val testCasesFactorial = [ - (factorial, 0, 1), (* 0! = 1 *) - (factorial, 1, 1), (* 1! = 1 *) - (factorial, 2, 2), (* 2! = 2 *) - (factorial, 3, 6), (* 3! = 6 *) - (factorial, 4, 24), (* 4! = 24 *) - (factorial, 5, 120), (* 5! = 120 *) - (factorial, 6, 720), (* 6! = 720 *) - (factorial, 7, 5040), (* 7! = 5040 *) - (factorial, 8, 40320), (* 8! = 40320 *) - (factorial, 10, 3628800) (* 10! = 3628800 *) -]; -runTestCasesIntInt(testCasesFactorial); - -val testCasesFib = [ - (* a_n = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55} *) - (fib, 0, 0), - (fib, 1, 1), - (fib, 2, 1), - (fib, 3, 2), - (fib, 4, 3), - (fib, 5, 5), - (fib, 6, 8), - (fib, 7, 13), - (fib, 8, 21), - (fib, 9, 34), - (fib, 10, 55) -]; -runTestCasesIntInt(testCasesFib); - -val testCasesCountZeros = [ - (countZeros, [0, 1, 0, 1, 0], 3), - (countZeros, [1, 1, 1, 1, 1], 0), - (countZeros, [0, 0, 0, 0, 0], 5), - (countZeros, [], 0), - (countZeros, [0], 1), - (countZeros, [1], 0), - (countZeros, [0, 0, 0, 1, 0], 4), - (countZeros, [1, 0, 1, 0, 1], 2), - (countZeros, [0, 0, 1, 0, 0, 0], 5) -]; -runTestCasesIntListInt(testCasesCountZeros); - -val testCasesOrList = [ - (orList, [true, true, true], true), - (orList, [true, false, true], true), - (orList, [false, false, false], false), - (orList, [true, true, false], true), - (orList, [false, false, true], true), - (orList, [false, false, false, false], false), - (orList, [false, true, false, true], true), - (orList, [], false), (* Empty list case *) - (orList, [false], false), (* Single false element *) - (orList, [true], true) (* Single true element *) -]; -runTestCasesBoolListBool(testCasesOrList); - -val testCasesAndList = [ - (andList, [true, true, true], true), - (andList, [true, false, true], false), - (andList, [false, false, false], false), - (andList, [], true), (* Empty list case *) - (andList, [true], true), - (andList, [false], false) -]; -runTestCasesBoolListBool(testCasesAndList); - -val testCasesAddLists = [ - (addLists, ([1, 2, 3], [4, 5, 6]), [5, 7, 9]), - (addLists, ([1, 2], [4, 5, 6]), [5, 7, 6]), - (addLists, ([1, 2, 3], []), [1, 2, 3]), - (addLists, ([], [4, 5, 6]), [4, 5, 6]), - (addLists, ([], []), []), - (addLists, ([1, 2, 3], [4, 5, 6, 7]), [5, 7, 9, 7]), - (addLists, ([1, 2, 3, 4, 5], [4, 5, 6]), [5, 7, 9, 4, 5]) -]; -runTestCasesIntListIntList(testCasesAddLists); - -val testCasesReverseList = [ - (reverseList, [1, 2, 3], [3, 2, 1]), - (reverseList, [1], [1]), - (reverseList, [], []), - (reverseList, [4, 5, 6, 7], [7, 6, 5, 4]), - (reverseList, [1, 2, 3, 4, 5], [5, 4, 3, 2, 1]), - (reverseList, [1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1]), - (reverseList, [1, 0, 0, 1, 0], [0, 1, 0, 0, 1]), - (reverseList, [0, 0, 0], [0, 0, 0]) -]; -runTestCasesIntListIntList(testCasesReverseList); - -fun removeZeros([]) = [] - | removeZeros(li) = - if hd(li) = 0 then removeZeros(tl(li)) - else hd(li) :: removeZeros(tl(li)); - -val testCasesRemoveZeros = [ - (removeZeros, [0, 1, 0, 2], [1, 2]), - (removeZeros, [0, 0, 0], []), - (removeZeros, [1, 2, 3], [1, 2, 3]), - (removeZeros, [], []), - (removeZeros, [0], []), - (removeZeros, [1], [1]), - (removeZeros, [0, 0, 0, 1, 0], [1]), - (removeZeros, [1, 0, 1, 0, 1], [1, 1, 1]) -]; -runTestCasesIntListIntList(testCasesRemoveZeros); - -fun mockAdd(x, y) = x + y; -fun mockModulus(x, y) = x mod y; -fun mockDiv(x, y) = x div y; -fun doNothing(x, y) = x; - -val testCasesCombineLists = [ - (combineLists, [1, 2, 3], [4, 5, 6], mockAdd, [5, 7, 9]), - (combineLists, [1, 2], [4, 5, 6], mockAdd, [5, 7, 6]), - (combineLists, [1, 2, 3], [], mockAdd, [1, 2, 3]), - (combineLists, [], [4, 5, 6], mockAdd, [4, 5, 6]), - (combineLists, [], [], mockAdd, []), - (combineLists, [1, 2, 3], [4, 5, 6], mockModulus, [1, 2, 3]), - (combineLists, [1, 2], [4, 5, 6], mockModulus, [1, 2, 6]), - (combineLists, [1, 2, 3], [], mockModulus, [1, 2, 3]), - (combineLists, [], [4, 5, 6], mockModulus, [4, 5, 6]), - (combineLists, [], [], mockModulus, []), - (combineLists, [1, 2, 3], [4, 5, 6], mockDiv, [0, 0, 0]), - (combineLists, [1, 2], [4, 5, 6], mockDiv, [0, 0, 6]), - (combineLists, [1, 2, 3], [], mockDiv, [1, 2, 3]), - (combineLists, [], [4, 5, 6], mockDiv, [4, 5, 6]), - (combineLists, [], [], mockDiv, []), - (combineLists, [1, 2, 3], [4, 5, 6], doNothing, [1, 2, 3]), - (combineLists, [1, 2], [4, 5, 6], doNothing, [1, 2, 6]), - (combineLists, [1, 2, 3], [], doNothing, [1, 2, 3]), - (combineLists, [], [4, 5, 6], doNothing, [4, 5, 6]), - (combineLists, [], [], doNothing, []) -]; -runTestCasesIntListIntListOperatorToIntList(testCasesCombineLists);