Skip to content

Commit

Permalink
simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Dec 16, 2024
1 parent e25a30e commit 4648d15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@
public class NullishCoalescingOpTest {
@Test
public void testNullishCoalescingOperatorRequiresES6() {
Utils.runWithAllOptimizationLevels(
cx -> {
Scriptable scope = cx.initStandardObjects();
assertThrows(
EvaluatorException.class,
() -> cx.evaluateString(scope, "true ?? false", "test.js", 0, null));
return null;
});
Utils.assertEvaluatorException_1_8("syntax error (test#1)", "true ?? false");
}

@Test
Expand Down Expand Up @@ -75,16 +68,7 @@ public void testNullishCoalescingDoesNotLeakVariables() {

@Test
public void testNullishAssignmentRequiresES6() {
Utils.runWithAllOptimizationLevels(
cx -> {
Scriptable scope = cx.initStandardObjects();
assertThrows(
EvaluatorException.class,
() ->
cx.evaluateString(
scope, "a = true; a ??= false", "test.js", 0, null));
return null;
});
Utils.assertEvaluatorException_1_8("syntax error (test#1)", "a = true; a ??= false");
}

@Test
Expand Down
4 changes: 4 additions & 0 deletions tests/src/test/java/org/mozilla/javascript/tests/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ private static <T extends Exception> void assertException(
final Class<T> expectedThrowable,
final String expectedMessage,
String js) {

// to avoid false positives because we use startsWith()
assertTrue("expectedMessage can't be empty",expectedMessage != null && !expectedMessage.isEmpty());

Utils.runWithAllOptimizationLevels(
cx -> {
if (languageVersion > -1) {
Expand Down

0 comments on commit 4648d15

Please sign in to comment.