Skip to content

Commit e7393d3

Browse files
committed
Implement fast assertions for non-identity tests.
1 parent 29db579 commit e7393d3

File tree

8 files changed

+41
-19
lines changed

8 files changed

+41
-19
lines changed

truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ErrorTypeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public void testErrorType() {
238238
testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray());
239239
} catch (PolyglotException pe) {
240240
try {
241-
TestUtil.validateResult(testRun, null, pe);
241+
TestUtil.validateResult(testRun, null, pe, true);
242242
} catch (PolyglotException | AssertionError e) {
243243
if (pe.equals(e)) {
244244
passed = true;

truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ExpressionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ public void testExpression() {
100100
try {
101101
try {
102102
final Value result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray());
103-
TestUtil.validateResult(testRun, result, null);
103+
TestUtil.validateResult(testRun, result, null, true);
104104
success = true;
105105
} catch (PolyglotException pe) {
106-
TestUtil.validateResult(testRun, null, pe);
106+
TestUtil.validateResult(testRun, null, pe, true);
107107
success = true;
108108
}
109109
} catch (PolyglotException | AssertionError e) {

truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/IdentityFunctionTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,11 @@ public void testIdentityFunction() {
107107
boolean success = false;
108108
try {
109109
try {
110-
111110
final Value result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray());
112-
TestUtil.validateResult(testRun, result, null);
111+
TestUtil.validateResult(testRun, result, null, false);
113112
success = true;
114113
} catch (PolyglotException pe) {
115-
TestUtil.validateResult(testRun, null, pe);
114+
TestUtil.validateResult(testRun, null, pe, false);
116115
success = true;
117116
}
118117
} catch (PolyglotException | AssertionError e) {

truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/InlineExecutionTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ public void testInline() throws Exception {
102102
try {
103103
try {
104104
final Value result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray());
105-
TestUtil.validateResult(testRun, result, null);
105+
TestUtil.validateResult(testRun, result, null, true);
106106
success = true;
107107
} catch (PolyglotException pe) {
108-
TestUtil.validateResult(testRun, null, pe);
108+
TestUtil.validateResult(testRun, null, pe, true);
109109
success = true;
110110
}
111111
if (verifier != null && verifier.exception != null) {
@@ -133,14 +133,14 @@ private class TestResultVerifier implements InlineVerifier.ResultVerifier {
133133
public void verify(Object ret) {
134134
Value result = context.getValue(ret);
135135
InlineSnippet inlineSnippet = testRun.getInlineSnippet();
136-
TestUtil.validateResult(inlineSnippet.getResultVerifier(), testRun, result, null);
136+
TestUtil.validateResult(inlineSnippet.getResultVerifier(), testRun, result, null, true);
137137
}
138138

139139
@Override
140140
public void verify(PolyglotException pe) {
141141
InlineSnippet inlineSnippet = testRun.getInlineSnippet();
142142
try {
143-
TestUtil.validateResult(inlineSnippet.getResultVerifier(), testRun, null, pe);
143+
TestUtil.validateResult(inlineSnippet.getResultVerifier(), testRun, null, pe, true);
144144
} catch (Exception exc) {
145145
exception = exc;
146146
}

truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ScriptTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ public void testScript() {
9191
try {
9292
try {
9393
final Value result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray());
94-
TestUtil.validateResult(testRun, result, null);
94+
TestUtil.validateResult(testRun, result, null, true);
9595
success = true;
9696
} catch (PolyglotException pe) {
97-
TestUtil.validateResult(testRun, null, pe);
97+
TestUtil.validateResult(testRun, null, pe, true);
9898
success = true;
9999
}
100100
} finally {

truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/StatementTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ public void testStatement() {
100100
try {
101101
try {
102102
final Value result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray());
103-
TestUtil.validateResult(testRun, result, null);
103+
TestUtil.validateResult(testRun, result, null, true);
104104
success = true;
105105
} catch (PolyglotException pe) {
106-
TestUtil.validateResult(testRun, null, pe);
106+
TestUtil.validateResult(testRun, null, pe, true);
107107
success = true;
108108
}
109109
} catch (PolyglotException | AssertionError e) {

truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/TestUtil.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,28 +137,38 @@ static Collection<? extends TestRun> createTestRuns(
137137
static void validateResult(
138138
final TestRun testRun,
139139
final Value result,
140-
final PolyglotException exception) {
140+
final PolyglotException exception,
141+
boolean fastAssertions) {
141142
ResultVerifier verifier = testRun.getSnippet().getResultVerifier();
142-
validateResult(verifier, testRun, result, exception);
143+
validateResult(verifier, testRun, result, exception, fastAssertions);
143144
}
144145

145146
static void validateResult(
146147
final ResultVerifier verifier,
147148
final TestRun testRun,
148149
final Value result,
149-
final PolyglotException exception) {
150+
final PolyglotException exception,
151+
boolean fastAssertions) {
150152
if (exception == null) {
151153
verifier.accept(ResultVerifier.SnippetRun.create(testRun.getSnippet(), testRun.getActualParameters(), result));
152-
ValueAssert.assertValue(result);
154+
assertValue(result, fastAssertions);
153155
} else {
154156
verifier.accept(ResultVerifier.SnippetRun.create(testRun.getSnippet(), testRun.getActualParameters(), exception));
155157
Value exceptionObject = exception.getGuestObject();
156158
if (exceptionObject != null) {
157-
ValueAssert.assertValue(exceptionObject);
159+
assertValue(exceptionObject, fastAssertions);
158160
}
159161
}
160162
}
161163

164+
private static void assertValue(final Value result, boolean fastAssertions) {
165+
if (fastAssertions) {
166+
ValueAssert.assertValueFast(result);
167+
} else {
168+
ValueAssert.assertValue(result);
169+
}
170+
}
171+
162172
static List<List<Map.Entry<String, ? extends Snippet>>> findApplicableParameters(
163173
final Snippet operator,
164174
final Collection<Map.Entry<String, ? extends Snippet>> valueConstructors) {

truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ValueAssert.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ public static void assertValue(Value value, boolean hasHostAccess, Trait... expe
140140
}
141141
}
142142

143+
public static void assertValueFast(Value value) {
144+
try {
145+
/*
146+
* The idea is that type detection triggers all type checks which triggers basic
147+
* assertions.
148+
*/
149+
detectSupportedTypes(value);
150+
} catch (AssertionError e) {
151+
e.addSuppressed(new AssertionError(String.format("assertValue: %s", value)));
152+
throw e;
153+
}
154+
}
155+
143156
public static void assertUnsupported(Value value, Trait... supported) {
144157
Set<Trait> supportedSet = new HashSet<>(Arrays.asList(supported));
145158
for (Trait unsupportedType : Trait.values()) {

0 commit comments

Comments
 (0)