Skip to content

Commit

Permalink
[GR-29902] Improve error message when TCK tests are executed with exp…
Browse files Browse the repository at this point in the history
…licitly entered context.

PullRequest: graal/8448
  • Loading branch information
tzezula committed Mar 15, 2021
2 parents 3abd476 + 3250e24 commit c77430f
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.util.TreeSet;
import java.util.function.Function;
import org.graalvm.polyglot.PolyglotException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -86,6 +87,11 @@ public static Collection<? extends TestRun> createErrorTypeTests() {
return testRuns;
}

@BeforeClass
public static void setUpClass() {
TestUtil.assertNoCurrentContext();
}

@AfterClass
public static void afterClass() throws IOException {
context.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.function.Function;
import org.graalvm.polyglot.Value;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -82,6 +83,11 @@ public Collection<? extends Snippet> apply(String lang) {
return testRuns;
}

@BeforeClass
public static void setUpClass() {
TestUtil.assertNoCurrentContext();
}

@AfterClass
public static void afterClass() throws IOException {
context.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.graalvm.polyglot.tck.Snippet;
import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -90,6 +91,11 @@ static Snippet createIdentitySnippet(String lang) {
return tli.createIdentityFunctionSnippet(context.getContext());
}

@BeforeClass
public static void setUpClass() {
TestUtil.assertNoCurrentContext();
}

@AfterClass
public static void afterClass() throws IOException {
context.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand All @@ -75,6 +76,11 @@ public static Collection<InlineTestRun> createScriptTests() {
return res;
}

@BeforeClass
public static void setUpClass() {
TestUtil.assertNoCurrentContext();
}

@AfterClass
public static void afterClass() throws IOException {
context.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.graalvm.polyglot.PolyglotException;
import org.graalvm.polyglot.Source;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand All @@ -74,6 +75,11 @@ public static Collection<Object[]> createInvalidSyntaxTests() {
return result;
}

@BeforeClass
public static void setUpClass() {
TestUtil.assertNoCurrentContext();
}

@AfterClass
public static void afterClass() throws IOException {
context.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.Objects;
import java.util.TreeSet;
import org.graalvm.polyglot.Value;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.graalvm.polyglot.PolyglotException;
Expand All @@ -73,6 +74,11 @@ public static Collection<TestRun> createScriptTests() {
return res;
}

@BeforeClass
public static void setUpClass() {
TestUtil.assertNoCurrentContext();
}

@AfterClass
public static void afterClass() throws IOException {
context.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.Objects;
import java.util.function.Function;
import org.graalvm.polyglot.Value;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.graalvm.polyglot.PolyglotException;
Expand Down Expand Up @@ -82,6 +83,11 @@ public Collection<? extends Snippet> apply(String lang) {
return testRuns;
}

@BeforeClass
public static void setUpClass() {
TestUtil.assertNoCurrentContext();
}

@AfterClass
public static void afterClass() throws IOException {
context.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.PolyglotException;
import org.graalvm.polyglot.SourceSection;
import org.graalvm.polyglot.Value;
Expand All @@ -72,6 +74,16 @@ private TestUtil() {
throw new IllegalStateException("No instance allowed.");
}

static void assertNoCurrentContext() {
try {
Context ctx = Context.getCurrent();
throw new AssertionError(String.format(
"Context cannot be explicitly entered while running TCK tests. Entered context: 0x%x", ctx.hashCode()));
} catch (IllegalStateException e) {
// No context entered.
}
}

static Set<? extends String> getRequiredLanguages(final TestContext context) {
Set<String> installedProviders = context.getInstalledProviders().keySet();
if (LANGUAGE != null && !installedProviders.contains(LANGUAGE)) {
Expand Down

0 comments on commit c77430f

Please sign in to comment.