Skip to content

Commit

Permalink
Move TestBase into a new project test-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Akirathan committed May 22, 2024
1 parent ba2787c commit 5bbd576
Show file tree
Hide file tree
Showing 45 changed files with 592 additions and 200 deletions.
9 changes: 9 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,7 @@ lazy val `runtime-integration-tests` =
.dependsOn(`logging-service-logback` % "test->test")
.dependsOn(testkit % Test)
.dependsOn(`connected-lock-manager-server`)
.dependsOn(`test-utils`)

/** A project that holds only benchmarks for `runtime`. Unlike `runtime-integration-tests`, its execution requires
* the whole `runtime-fat-jar` assembly, as we want to be as close to the enso distribution as possible.
Expand Down Expand Up @@ -2578,6 +2579,14 @@ lazy val `distribution-manager` = project
.dependsOn(pkg)
.dependsOn(`logging-utils`)

lazy val `test-utils` =
(project in file("lib/java/test-utils"))
.settings(
frgaalJavaCompilerSetting,
libraryDependencies ++= GraalVM.modules
)
.dependsOn(runtime)

lazy val `benchmarks-common` =
(project in file("lib/java/benchmarks-common"))
.settings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.enso.compiler.core.ir.module.scope.Export;
import org.enso.compiler.core.ir.module.scope.definition.Method;
import org.enso.interpreter.runtime.EnsoContext;
import org.enso.interpreter.test.TestBase;
import org.enso.polyglot.RuntimeOptions;
import org.enso.test.utils.TestUtils;
import org.graalvm.polyglot.Context;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand All @@ -36,7 +36,7 @@
* symbols are tested. For example the builtin types are not tested.
*/
@RunWith(Parameterized.class)
public class ImportsAndFQNConsistencyTest extends TestBase {
public class ImportsAndFQNConsistencyTest {
private static Context ctx;

/** Used for description in {@link PrintCodeRule} test rule. */
Expand All @@ -51,17 +51,17 @@ public class ImportsAndFQNConsistencyTest extends TestBase {
@Parameters(name = "exported symbol '{0}'")
public static List<Symbol> symbolsToTest() {
try (var ctx =
TestBase.defaultContextBuilder(LanguageInfo.ID)
TestUtils.defaultContextBuilder(LanguageInfo.ID)
.option(RuntimeOptions.DISABLE_IR_CACHES, "false")
.build()) {
var ensoCtx = TestBase.leakContext(ctx);
var ensoCtx = TestUtils.leakContext(ctx);
var src = """
from Standard.Base import all
from Standard.Table import all
main = 42
""";
// Ensure that the context is initialized first.
var res = TestBase.evalModule(ctx, src);
var res = TestUtils.evalModule(ctx, src);
assertThat(res.isNumber(), is(true));
List<Symbol> symbolsToTest = new ArrayList<>();
gatherExportedSymbols(ensoCtx, List.of("Standard.Base.Main", "Standard.Table.Main")).stream()
Expand Down Expand Up @@ -94,7 +94,7 @@ public static List<Symbol> symbolsToTest() {

@BeforeClass
public static void initCtx() {
ctx = TestBase.createDefaultContext();
ctx = TestUtils.createDefaultContext();
}

@AfterClass
Expand All @@ -109,7 +109,7 @@ public ImportsAndFQNConsistencyTest(Symbol symbol) {
}

private void evalCode(Symbol symbol) {
var res = TestBase.evalModule(ctx, code);
var res = TestUtils.evalModule(ctx, code);
assertThat(res.isString(), is(true));
assertThat(res.asString(), is(symbol.getLastPathItem()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@
import org.enso.common.MethodNames;
import org.enso.compiler.CompilerTest;
import org.enso.interpreter.runtime.EnsoContext;
import org.enso.interpreter.test.TestBase;
import org.enso.polyglot.RuntimeOptions;
import org.enso.test.utils.TestUtils;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Source;
import org.junit.BeforeClass;
import org.junit.Test;

public class ModuleCacheTest extends TestBase {
public class ModuleCacheTest {
private static Context ctx;

public ModuleCacheTest() {}

@BeforeClass
public static void initializeContext() throws Exception {
ctx = defaultContextBuilder().option(RuntimeOptions.DISABLE_IR_CACHES, "true").build();
ctx =
TestUtils.defaultContextBuilder().option(RuntimeOptions.DISABLE_IR_CACHES, "true").build();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
import org.enso.interpreter.runtime.data.atom.AtomNewInstanceNode;
import org.enso.interpreter.runtime.data.atom.StructsLibrary;
import org.enso.interpreter.runtime.error.PanicException;
import org.enso.test.utils.TestUtils;
import org.graalvm.polyglot.Context;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class AtomConstructorTest extends TestBase {
public class AtomConstructorTest {

private static Context ctx;

public AtomConstructorTest() {}

@BeforeClass
public static void initContext() {
ctx = createDefaultContext();
ctx = TestUtils.createDefaultContext();
}

@AfterClass
Expand All @@ -40,7 +41,7 @@ public void testGetUncached() {
""";
var module = ctx.eval("enso", code);
var consA = module.invokeMember(MethodNames.Module.EVAL_EXPRESSION, "NoPrime.A");
var raw = unwrapValue(ctx, consA);
var raw = TestUtils.unwrapValue(ctx, consA);

assertTrue("It is atom constructor: " + raw, raw instanceof AtomConstructor);
var cons = (AtomConstructor) raw;
Expand All @@ -59,7 +60,7 @@ public void testAtomNewInstanceNode() {
""";
var module = ctx.eval("enso", code);
var xA = module.invokeMember(MethodNames.Module.EVAL_EXPRESSION, "X.A");
var raw = unwrapValue(ctx, xA);
var raw = TestUtils.unwrapValue(ctx, xA);

assertTrue("It is atom constructor: " + raw, raw instanceof AtomConstructor);
var cons = (AtomConstructor) raw;
Expand Down Expand Up @@ -137,7 +138,7 @@ private static void assertAtomFactory(String msg, Function<java.lang.Object[], A
}

private static void assertLessArguments(String msg, Function<Object[], Atom> factory) {
executeInContext(
TestUtils.executeInContext(
ctx,
() -> {
try {
Expand Down Expand Up @@ -181,7 +182,7 @@ public void endlessConstructors() throws Exception {
var module = ctx.eval("enso", sb.toString());
for (var i = 0; i < constructors.length; i++) {
var c = module.invokeMember(MethodNames.Module.EVAL_EXPRESSION, "T.V" + i);
constructors[i] = (AtomConstructor) unwrapValue(ctx, c);
constructors[i] = (AtomConstructor) TestUtils.unwrapValue(ctx, c);
}

var typeValue = ctx.asValue(constructors[0].getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@

import java.io.ByteArrayOutputStream;
import org.enso.common.MethodNames;
import org.enso.test.utils.TestUtils;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.PolyglotException;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class AutoscopedConstructorTest extends TestBase {
public class AutoscopedConstructorTest {
private static final ByteArrayOutputStream out = new ByteArrayOutputStream();
private static Context ctx;

public AutoscopedConstructorTest() {}

@BeforeClass
public static void prepareCtx() {
ctx = createDefaultContext(out);
ctx = TestUtils.createDefaultContext(out);
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import org.enso.test.utils.TestUtils;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.Value;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class BigNumberTest extends TestBase {
public class BigNumberTest {
private static Context ctx;

@BeforeClass
public static void prepareCtx() {
ctx = createDefaultContext();
ctx = TestUtils.createDefaultContext();
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.enso.common.MethodNames;
import org.enso.interpreter.runtime.error.PanicException;
import org.enso.test.utils.TestUtils;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.PolyglotException;
import org.graalvm.polyglot.Source;
Expand All @@ -17,15 +18,15 @@
import org.junit.BeforeClass;
import org.junit.Test;

public class BinaryDispatchTest extends TestBase {
public class BinaryDispatchTest {
private static Context ctx;
private static Value module;

public BinaryDispatchTest() {}

@BeforeClass
public static void initCtx() throws Exception {
ctx = createDefaultContext();
ctx = TestUtils.createDefaultContext();

var prelude =
Source.newBuilder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Random;
import java.util.stream.Stream;
import org.enso.common.MethodNames;
import org.enso.test.utils.TestUtils;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.PolyglotException;
import org.graalvm.polyglot.Value;
Expand All @@ -18,7 +19,7 @@
import org.junit.runners.Parameterized;

@RunWith(Parameterized.class)
public class BinaryOpFloatTest extends TestBase {
public class BinaryOpFloatTest {
private static final String[] OPERATIONS = {
" +", " -", " ^", " *", " %", " <=", " <", " >=", " >", " /"
};
Expand Down Expand Up @@ -56,7 +57,7 @@ public static Object[][] parameters() {

@BeforeClass
public static void initContext() {
ctx = createDefaultContext();
ctx = TestUtils.createDefaultContext();
wrapReal =
ctx.eval(
"enso",
Expand Down Expand Up @@ -102,7 +103,7 @@ public BinaryOpFloatTest(String operation, double n1, double n2) {

@Test
public void verifyOperationOnForeignObject() {
executeInContext(
TestUtils.executeInContext(
ctx,
() -> {
var code = """
Expand All @@ -122,7 +123,7 @@ public void verifyOperationOnForeignObject() {

@Test
public void verifyOperationWithConvertibleObject() {
executeInContext(
TestUtils.executeInContext(
ctx,
() -> {
var code = """
Expand All @@ -147,7 +148,7 @@ public void verifyOperationWithConvertibleObject() {

@Test
public void verifyOperationOnConvertibleObject() {
executeInContext(
TestUtils.executeInContext(
ctx,
() -> {
var code = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Random;
import java.util.stream.Stream;
import org.enso.common.MethodNames;
import org.enso.test.utils.TestUtils;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
import org.junit.AfterClass;
Expand All @@ -17,7 +18,7 @@
import org.junit.runners.Parameterized;

@RunWith(Parameterized.class)
public class BinaryOpIntegerTest extends TestBase {
public class BinaryOpIntegerTest {
private static final String[] OPERATIONS = {
" +",
" -",
Expand Down Expand Up @@ -70,7 +71,7 @@ public static Object[][] parameters() {

@BeforeClass
public static void initContext() {
ctx = createDefaultContext();
ctx = TestUtils.createDefaultContext();
wrapInt =
ctx.eval(
"enso",
Expand Down Expand Up @@ -121,7 +122,7 @@ public BinaryOpIntegerTest(String operation, long n1, long n2) {

@Test
public void verifyOperationOnForeignObject() {
executeInContext(
TestUtils.executeInContext(
ctx,
() -> {
var code = """
Expand All @@ -141,7 +142,7 @@ public void verifyOperationOnForeignObject() {

@Test
public void verifyOperationWithConvertibleObject() {
executeInContext(
TestUtils.executeInContext(
ctx,
() -> {
var code = """
Expand All @@ -168,7 +169,7 @@ public void verifyOperationWithConvertibleObject() {

@Test
public void verifyOperationOnConvertibleObject() {
executeInContext(
TestUtils.executeInContext(
ctx,
() -> {
var code = """
Expand Down
Loading

0 comments on commit 5bbd576

Please sign in to comment.