From dd2d5ae90e2b855263dcd00d75021ee11654b40e Mon Sep 17 00:00:00 2001 From: stoutes <31317041+stoutes@users.noreply.github.com> Date: Fri, 23 Jan 2026 18:18:23 -0600 Subject: [PATCH 01/11] #28311 added overloads for unitTest.chpl Signed-off-by: stoutes <31317041+stoutes@users.noreply.github.com> --- modules/packages/UnitTest.chpl | 162 ++++++++++++++++++ .../packages/UnitTest/assertWithArgs.chpl | 99 +++++++++++ 2 files changed, 261 insertions(+) create mode 100644 test/library/packages/UnitTest/assertWithArgs.chpl diff --git a/modules/packages/UnitTest.chpl b/modules/packages/UnitTest.chpl index 7241efafce9a..b021cf910ff2 100644 --- a/modules/packages/UnitTest.chpl +++ b/modules/packages/UnitTest.chpl @@ -247,6 +247,33 @@ module UnitTest { throw new owned AssertionError("assertTrue failed. Given expression is False"); } + /* + Assert that ``test`` is `true`. If it is false, prints + 'assert failed' along with any additional arguments provided. + + :arg test: the boolean condition + :type test: `bool` + :arg args: additional values to print on failure + */ + pragma "insert line file info" + pragma "always propagate line file info" + proc assertTrue(test: bool, args...?n) throws { + if !test { + var msg = "assertTrue failed. Given expression is False"; + + // Append additional arguments to error message + if n > 0 { + msg += " - "; + for param i in 0.. 0 { + msg += " - "; + for param i in 0.. 0 { + msg += " - "; + for param i in 0.. 0 { + tmpString += " - "; + for param i in 0.. second``. @@ -581,6 +688,34 @@ module UnitTest { } } + /* + Assert that ``first > second``. If ``first <= second``, + prints the two values along with any additional arguments provided. + + :arg first: The first object to compare + :arg second: The second object to compare + :arg args: additional values to print on failure + */ + proc assertGreaterThan(first, second, args...?n) throws { + if first.type == second.type { + if first <= second { + var tmpString = "assert failed - " + stringify(first) + + " <= " + stringify(second); + + if n > 0 { + tmpString += " - "; + for param i in 0..= second``, + prints the two values along with any additional arguments provided. + + :arg first: The first object to compare + :arg second: The second object to compare + :arg args: additional values to print on failure + */ + proc assertLessThan(first, second, args...?n) throws { + if first.type == second.type { + if first >= second { + var tmpString = "assert failed - " + stringify(first) + + " >= " + stringify(second); + + if n > 0 { + tmpString += " - "; + for param i in 0..= 0); + } +} + +// Test assertFalse with extra args +proc testFalseWithArgs(test: borrowed Test) throws { + var y = 10; + test.assertFalse(false, "This should pass with extra args:", y); + + try { + test.assertFalse(true, "Expected false but got true, value:", y); + test.assertTrue(false, "Should not reach here"); + } catch e: AssertionError { + test.assertTrue(e.message().find("value:") >= 0); + } +} + +// Test assertEqual with extra args +proc testEqualWithArgs(test: borrowed Test) throws { + var a = 5, b = 5, c = 10; + test.assertEqual(a, b, "Values match:", a, "and", b); + + try { + test.assertEqual(a, c, "Expected a=", a, "to equal c=", c); + test.assertTrue(false, "Should not reach here"); + } catch e: AssertionError { + test.assertTrue(e.message().find("Expected a=") >= 0); + } +} + +// Test assertNotEqual with extra args +proc testNotEqualWithArgs(test: borrowed Test) throws { + var x = 5, y = 10; + test.assertNotEqual(x, y, "Values differ:", x, "and", y); + + try { + test.assertNotEqual(x, x, "Expected different values, got:", x); + test.assertTrue(false, "Should not reach here"); + } catch e: AssertionError { + test.assertTrue(e.message().find("Expected different") >= 0); + } +} + +// Test assertGreaterThan with extra args +proc testGreaterThanWithArgs(test: borrowed Test) throws { + var x = 10, y = 5; + test.assertGreaterThan(x, y, "x=", x, "is greater than y=", y); + + try { + test.assertGreaterThan(y, x, "Expected y=", y, "> x=", x); + test.assertTrue(false, "Should not reach here"); + } catch e: AssertionError { + test.assertTrue(e.message().find("Expected y=") >= 0); + } +} + +// Test assertLessThan with extra args +proc testLessThanWithArgs(test: borrowed Test) throws { + var x = 5, y = 10; + test.assertLessThan(x, y, "x=", x, "is less than y=", y); + + try { + test.assertLessThan(y, x, "Expected y=", y, "< x=", x); + test.assertTrue(false, "Should not reach here"); + } catch e: AssertionError { + test.assertTrue(e.message().find("Expected y=") >= 0); + } +} + +// Test with multiple types +proc testMixedTypes(test: borrowed Test) throws { + var i = 42; + var s = "hello"; + var r = 3.14; + + test.assertTrue(true, "Mixed types:", i, s, r); + + try { + test.assertEqual(i, 100, "int:", i, "string:", s, "real:", r); + } catch e: AssertionError { + test.assertTrue(e.message().find("string:") >= 0); + } +} + +UnitTest.main(); From 24b1f8f201f49e5fe32420c09f398c9f7bfde703 Mon Sep 17 00:00:00 2001 From: stoutes <31317041+stoutes@users.noreply.github.com> Date: Fri, 23 Jan 2026 18:18:51 -0600 Subject: [PATCH 02/11] forgot good file Signed-off-by: stoutes <31317041+stoutes@users.noreply.github.com> --- test/library/packages/UnitTest/assertWithArgs.good | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/library/packages/UnitTest/assertWithArgs.good diff --git a/test/library/packages/UnitTest/assertWithArgs.good b/test/library/packages/UnitTest/assertWithArgs.good new file mode 100644 index 000000000000..e69de29bb2d1 From 0a2fd8d03687dde075a26e49a2a8af4680a89dfa Mon Sep 17 00:00:00 2001 From: stoutes <31317041+stoutes@users.noreply.github.com> Date: Fri, 23 Jan 2026 19:51:33 -0600 Subject: [PATCH 03/11] getting rid of stringify() Signed-off-by: stoutes <31317041+stoutes@users.noreply.github.com> --- modules/packages/UnitTest.chpl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/packages/UnitTest.chpl b/modules/packages/UnitTest.chpl index b021cf910ff2..ed6564e17a54 100644 --- a/modules/packages/UnitTest.chpl +++ b/modules/packages/UnitTest.chpl @@ -652,9 +652,11 @@ module UnitTest { proc assertNotEqual(first, second, args...?n) throws { if first.type == second.type { if all(first == second) { - var tmpString = "assert failed - \n" + stringify(first) + - "\nequals \n" + stringify(second); + // Build the base error message + var tmpString = "assert failed - \n" + first:string + + "\nequals \n" + second:string; + // Append additional arguments if n > 0 { tmpString += " - "; for param i in 0..= second { - var tmpString = "assert failed - " + stringify(first) + - " >= " + stringify(second); + var tmpString = "assert failed - " + first:string + + " >= " + second:string; if n > 0 { tmpString += " - "; From 2fc9f1a198459c9ae0f518f43ee10e5bbc843bf0 Mon Sep 17 00:00:00 2001 From: stoutes <31317041+stoutes@users.noreply.github.com> Date: Fri, 23 Jan 2026 19:57:50 -0600 Subject: [PATCH 04/11] updating good file Signed-off-by: stoutes <31317041+stoutes@users.noreply.github.com> --- .../packages/UnitTest/assertWithArgs.good | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/library/packages/UnitTest/assertWithArgs.good b/test/library/packages/UnitTest/assertWithArgs.good index e69de29bb2d1..140b2d31a688 100644 --- a/test/library/packages/UnitTest/assertWithArgs.good +++ b/test/library/packages/UnitTest/assertWithArgs.good @@ -0,0 +1,25 @@ +testTrueWithArgs() +Flavour: OK +====================================================================== +---------------------------------------------------------------------- +testFalseWithArgs() +Flavour: OK +====================================================================== +---------------------------------------------------------------------- +testEqualWithArgs() +Flavour: OK +====================================================================== +---------------------------------------------------------------------- +testNotEqualWithArgs() +Flavour: OK +====================================================================== +---------------------------------------------------------------------- +testGreaterThanWithArgs() +Flavour: OK +====================================================================== +---------------------------------------------------------------------- +testLessThanWithArgs() +Flavour: OK +====================================================================== +---------------------------------------------------------------------- +EOF \ No newline at end of file From d59031bee5b30b92d4634f0ae325d8b4953794a2 Mon Sep 17 00:00:00 2001 From: stoutes <31317041+stoutes@users.noreply.github.com> Date: Fri, 23 Jan 2026 20:01:49 -0600 Subject: [PATCH 05/11] failure unit test Signed-off-by: stoutes <31317041+stoutes@users.noreply.github.com> --- .../library/packages/UnitTest/assertWithArgsFailure.chpl | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/library/packages/UnitTest/assertWithArgsFailure.chpl diff --git a/test/library/packages/UnitTest/assertWithArgsFailure.chpl b/test/library/packages/UnitTest/assertWithArgsFailure.chpl new file mode 100644 index 000000000000..a9f46aea0aa8 --- /dev/null +++ b/test/library/packages/UnitTest/assertWithArgsFailure.chpl @@ -0,0 +1,9 @@ +use UnitTest; + +proc testFailureMessage(test: borrowed Test) throws { + var x = 5, y = 10; + // This will fail and show our custom message + test.assertEqual(x, y, "Expected x=", x, "to equal y=", y); +} + +UnitTest.main(); \ No newline at end of file From 880e0747526b47d5f34c07581688e1862411a592 Mon Sep 17 00:00:00 2001 From: stoutes <31317041+stoutes@users.noreply.github.com> Date: Sat, 31 Jan 2026 11:48:51 -0600 Subject: [PATCH 06/11] new comments, refactored conditional logic, better error msgs, --- modules/packages/UnitTest.chpl | 148 +++++++++++++-------------------- 1 file changed, 56 insertions(+), 92 deletions(-) diff --git a/modules/packages/UnitTest.chpl b/modules/packages/UnitTest.chpl index ed6564e17a54..b7fbde3760bb 100644 --- a/modules/packages/UnitTest.chpl +++ b/modules/packages/UnitTest.chpl @@ -248,28 +248,22 @@ module UnitTest { } /* - Assert that ``test`` is `true`. If it is false, prints - 'assert failed' along with any additional arguments provided. + Assert that ``test`` is `true`. If it is false, adds the ``args`` to + the thrown error's ``message`` as if those args were printed using + :proc:`~IO.write()`. :arg test: the boolean condition :type test: `bool` :arg args: additional values to print on failure + :throws: AssertionError if the assertion fails */ pragma "insert line file info" pragma "always propagate line file info" + pragma "insert line file info" + pragma "always propagate line file info" proc assertTrue(test: bool, args...?n) throws { if !test { - var msg = "assertTrue failed. Given expression is False"; - - // Append additional arguments to error message - if n > 0 { - msg += " - "; - for param i in 0.. 0 { - msg += " - "; - for param i in 0.. 0 { - msg += " - "; - for param i in 0.. 0 { - tmpString += " - "; - for param i in 0.. second``. If ``first <= second``, - prints the two values along with any additional arguments provided. + Assert that ``first > second``. If ``first <= second``, adds the ``args`` + to the thrown error's ``message`` as if those args were printed using + :proc:`~IO.write()`. :arg first: The first object to compare :arg second: The second object to compare :arg args: additional values to print on failure + :throws: AssertionError if the assertion fails */ proc assertGreaterThan(first, second, args...?n) throws { - if first.type == second.type { - if first <= second { - var tmpString = "assert failed - " + first:string + - " <= " + second:string; - - if n > 0 { - tmpString += " - "; - for param i in 0..=", first, second) { + try { + checkGreater(first, second); + } catch e: AssertionError { + throw new owned AssertionError(e.message() + " - " + chpl_stringify_wrapper((...args))); } } - } + else { + throw new owned AssertionError("assert failed - First element is of type %? and Second is of type %? - ".format(first.type:string, second.type:string) + + chpl_stringify_wrapper((...args))); + } +} pragma "insert line file info" @@ -939,31 +906,28 @@ module UnitTest { } /* - Assert that ``first < second``. If ``first >= second``, - prints the two values along with any additional arguments provided. + Assert that ``first < second``. If ``first >= second``, adds the ``args`` + to the thrown error's ``message`` as if those args were printed using + :proc:`~IO.write()`. :arg first: The first object to compare :arg second: The second object to compare :arg args: additional values to print on failure + :throws: AssertionError if the assertion fails */ proc assertLessThan(first, second, args...?n) throws { - if first.type == second.type { - if first >= second { - var tmpString = "assert failed - " + first:string + - " >= " + second:string; - - if n > 0 { - tmpString += " - "; - for param i in 0.. Date: Sat, 31 Jan 2026 12:02:08 -0600 Subject: [PATCH 07/11] changed checkGreater and checkLess to checkGreaterThan and checkLessThan Signed-off-by: stoutes <31317041+stoutes@users.noreply.github.com> --- modules/packages/UnitTest.chpl | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/packages/UnitTest.chpl b/modules/packages/UnitTest.chpl index b7fbde3760bb..0a6f9874dbe9 100644 --- a/modules/packages/UnitTest.chpl +++ b/modules/packages/UnitTest.chpl @@ -650,15 +650,19 @@ module UnitTest { */ pragma "insert line file info" pragma "always propagate line file info" - proc assertGreaterThan(first, second) throws { - if canResolve(">=",first, second) { - checkGreater(first, second); + proc assertGreaterThan(first, second, args...?n) throws { + if canResolve(">=", first, second) { + try { + checkGreaterThan(first, second); // Changed from checkGreater + } catch e: AssertionError { + throw new owned AssertionError(e.message() + " - " + chpl_stringify_wrapper((...args))); + } } else { - const errorMsg = "assert failed - First element is of type %? and Second is of type %?".format(first.type:string, second.type:string); - throw new owned AssertionError(errorMsg); + throw new owned AssertionError("assert failed - First element is of type %? and Second is of type %? - ".format(first.type:string, second.type:string) + + chpl_stringify_wrapper((...args))); } - } +} /* Assert that ``first > second``. If ``first <= second``, adds the ``args`` @@ -918,7 +922,7 @@ module UnitTest { proc assertLessThan(first, second, args...?n) throws { if canResolve("<=", first, second) { try { - checkLess(first, second); + checkLessThan(first, second); // Changed from checkLess } catch e: AssertionError { throw new owned AssertionError(e.message() + " - " + chpl_stringify_wrapper((...args))); } From 400dcbb7ffeba6b0b89fa208a133f746d5673991 Mon Sep 17 00:00:00 2001 From: stoutes <31317041+stoutes@users.noreply.github.com> Date: Sat, 31 Jan 2026 12:09:22 -0600 Subject: [PATCH 08/11] fixed accidentally changing assertGreaterThan non-overload func Signed-off-by: stoutes <31317041+stoutes@users.noreply.github.com> --- modules/packages/UnitTest.chpl | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/modules/packages/UnitTest.chpl b/modules/packages/UnitTest.chpl index 0a6f9874dbe9..527cb08f33d5 100644 --- a/modules/packages/UnitTest.chpl +++ b/modules/packages/UnitTest.chpl @@ -650,19 +650,15 @@ module UnitTest { */ pragma "insert line file info" pragma "always propagate line file info" - proc assertGreaterThan(first, second, args...?n) throws { - if canResolve(">=", first, second) { - try { - checkGreaterThan(first, second); // Changed from checkGreater - } catch e: AssertionError { - throw new owned AssertionError(e.message() + " - " + chpl_stringify_wrapper((...args))); - } + proc assertGreaterThan(first, second) throws { + if canResolve(">=",first, second) { + checkGreater(first, second); } else { - throw new owned AssertionError("assert failed - First element is of type %? and Second is of type %? - ".format(first.type:string, second.type:string) + - chpl_stringify_wrapper((...args))); + const errorMsg = "assert failed - First element is of type %? and Second is of type %?".format(first.type:string, second.type:string); + throw new owned AssertionError(errorMsg); } -} + } /* Assert that ``first > second``. If ``first <= second``, adds the ``args`` From b30bd558a0b5e79a7346def35aa2137440515e9e Mon Sep 17 00:00:00 2001 From: stoutes <31317041+stoutes@users.noreply.github.com> Date: Sat, 31 Jan 2026 12:19:42 -0600 Subject: [PATCH 09/11] added and verified .good file for assertWithArgsFailure Signed-off-by: stoutes <31317041+stoutes@users.noreply.github.com> --- test/library/packages/UnitTest/assertWithArgsFailure.good | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 test/library/packages/UnitTest/assertWithArgsFailure.good diff --git a/test/library/packages/UnitTest/assertWithArgsFailure.good b/test/library/packages/UnitTest/assertWithArgsFailure.good new file mode 100644 index 000000000000..182859d860c4 --- /dev/null +++ b/test/library/packages/UnitTest/assertWithArgsFailure.good @@ -0,0 +1,5 @@ +testFailureMessage() +Flavour: FAIL +====================================================================== +AssertionError: in assertWithArgsFailure.chpl:6 - in assertWithArgsFailure.chpl:6 - assert failed - '5' != '10' - Expected x=5to equal y=10 +---------------------------------------------------------------------- From 3e088a000968bb560297ae4d94a3a00818ef9f4b Mon Sep 17 00:00:00 2001 From: stoutes <31317041+stoutes@users.noreply.github.com> Date: Tue, 3 Feb 2026 18:43:42 -0600 Subject: [PATCH 10/11] formatting UnitTest.chpl --- modules/packages/UnitTest.chpl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/packages/UnitTest.chpl b/modules/packages/UnitTest.chpl index 527cb08f33d5..0b28c962a1dd 100644 --- a/modules/packages/UnitTest.chpl +++ b/modules/packages/UnitTest.chpl @@ -530,8 +530,8 @@ module UnitTest { } catch e: AssertionError { var msg = e.message() + " - " + chpl_stringify_wrapper((...args)); throw new owned AssertionError(msg); - } - } + } + } /* Assert that x matches the regular expression pattern. @@ -638,7 +638,7 @@ module UnitTest { chpl_stringify_wrapper((...args))); } } -} + } /* @@ -682,7 +682,7 @@ module UnitTest { throw new owned AssertionError("assert failed - First element is of type %? and Second is of type %? - ".format(first.type:string, second.type:string) + chpl_stringify_wrapper((...args))); } -} + } pragma "insert line file info" @@ -918,7 +918,7 @@ module UnitTest { proc assertLessThan(first, second, args...?n) throws { if canResolve("<=", first, second) { try { - checkLessThan(first, second); // Changed from checkLess + checkLessThan(first, second); } catch e: AssertionError { throw new owned AssertionError(e.message() + " - " + chpl_stringify_wrapper((...args))); } @@ -927,7 +927,7 @@ module UnitTest { throw new owned AssertionError("assert failed - First element is of type %? and Second is of type %? - ".format(first.type:string, second.type:string) + chpl_stringify_wrapper((...args))); } -} + } pragma "insert line file info" pragma "always propagate line file info" From 9374018e0240a9589249803cc2923b1a57415fdd Mon Sep 17 00:00:00 2001 From: stoutes <31317041+stoutes@users.noreply.github.com> Date: Tue, 3 Feb 2026 19:34:37 -0600 Subject: [PATCH 11/11] fixed indentation in UnitTest.chpl --- modules/packages/UnitTest.chpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/packages/UnitTest.chpl b/modules/packages/UnitTest.chpl index 0b28c962a1dd..1a211af736da 100644 --- a/modules/packages/UnitTest.chpl +++ b/modules/packages/UnitTest.chpl @@ -528,8 +528,8 @@ module UnitTest { try { checkAssertEquality(first, second); } catch e: AssertionError { - var msg = e.message() + " - " + chpl_stringify_wrapper((...args)); - throw new owned AssertionError(msg); + var msg = e.message() + " - " + chpl_stringify_wrapper((...args)); + throw new owned AssertionError(msg); } }