Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor runtime-integration-tests - move some tests to more dedicated packages #11720

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.enso.interpreter.test;
package org.enso.interpreter.test.hash;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
Expand All @@ -13,6 +13,7 @@
import org.enso.interpreter.node.expression.builtin.meta.HashCodeNodeGen;
import org.enso.interpreter.node.expression.foreign.HostValueToEnsoNode;
import org.enso.interpreter.runtime.EnsoContext;
import org.enso.interpreter.test.ValuesGenerator;
import org.enso.test.utils.ContextUtils;
import org.enso.test.utils.TestRootNode;
import org.graalvm.polyglot.Context;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.enso.interpreter.test;
package org.enso.interpreter.test.instrument;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.enso.interpreter.test;
package org.enso.interpreter.test.interop;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.enso.interpreter.test;
package org.enso.interpreter.test.interop;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.enso.interpreter.test;
package org.enso.interpreter.test.interop;

import static org.junit.Assert.assertEquals;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.enso.interpreter.test;
package org.enso.interpreter.test.interop;

import org.enso.interpreter.test.ValuesGenerator;
import org.enso.interpreter.test.ValuesGenerator.Language;
import org.graalvm.polyglot.Context;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.enso.interpreter.test;
package org.enso.interpreter.test.interop;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -20,6 +20,7 @@
import org.enso.common.MethodNames;
import org.enso.interpreter.runtime.data.Type;
import org.enso.interpreter.runtime.type.ConstantsGen;
import org.enso.interpreter.test.ValuesGenerator;
import org.enso.interpreter.test.ValuesGenerator.Language;
import org.enso.test.utils.ContextUtils;
import org.graalvm.polyglot.Context;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.enso.interpreter.test;
package org.enso.interpreter.test.interop;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package org.enso.interpreter.test.interop;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

import java.util.ArrayList;
import java.util.Objects;
import org.enso.interpreter.runtime.data.Type;
import org.enso.interpreter.test.ValuesGenerator;
import org.enso.interpreter.test.ValuesGenerator.Language;
import org.enso.test.utils.ContextUtils;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

/**
* Tests that every {@link org.enso.interpreter.runtime.data.Type} exposes its constructors as
* {@link com.oracle.truffle.api.interop.InteropLibrary#getMembers(Object) members}, and that such
* members are {@link com.oracle.truffle.api.interop.InteropLibrary#isInstantiable(Object)
* instantiable}.
*/
@RunWith(Parameterized.class)
public class TypesExposeConstructorsTest {
private static Context ctx;

private final TypeWithWrapper typeWithWrapper;

public TypesExposeConstructorsTest(TypeWithWrapper typeWithWrapper) {
this.typeWithWrapper = typeWithWrapper;
}

private static Context ctx() {
if (ctx == null) {
ctx = ContextUtils.createDefaultContext();
}
return ctx;
}

@AfterClass
public static void disposeCtx() {
if (ctx != null) {
ctx.close();
ctx = null;
}
}

@Parameters(name = "{index}: {0}")
public static Iterable<TypeWithWrapper> collectTypes() {
var collectedTypes = new ArrayList<TypeWithWrapper>();
ContextUtils.executeInContext(
ctx(),
() -> {
var valuesGenerator = ValuesGenerator.create(ctx(), Language.ENSO);
valuesGenerator.allTypes().stream()
.map(
tp -> {
var unwrappedTp = ContextUtils.unwrapValue(ctx(), tp);
if (unwrappedTp instanceof Type type) {
return new TypeWithWrapper(type, tp);
} else {
return null;
}
})
.filter(Objects::nonNull)
.filter(tp -> !tp.type.getConstructors().isEmpty())
.forEach(collectedTypes::add);
return null;
});
return collectedTypes;
}

@Test
public void typesExposeConstructorsAsMembers() {
var type = typeWithWrapper.type;
var typeValue = typeWithWrapper.typeValue;
var consNames = type.getConstructors().keySet();
for (var consName : consNames) {
assertThat(
"Constructor " + consName + " should be exposed as a member",
typeValue.hasMember(consName),
is(true));
var consMember = typeValue.getMember(consName);
assertThat(consMember, is(notNullValue()));
assertThat(
"Constructor " + consName + " should be instantiable",
consMember.canInstantiate(),
is(true));
}
}

/**
* @param type
* @param typeValue The polyglot value of the type (not an object)
*/
public record TypeWithWrapper(Type type, Value typeValue) {}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.enso.interpreter.test;
package org.enso.interpreter.test.meta;

import org.enso.interpreter.test.ValuesGenerator;
import org.enso.interpreter.test.ValuesGenerator.Language;
import org.graalvm.polyglot.Context;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.enso.interpreter.test;
package org.enso.interpreter.test.meta;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -10,6 +10,7 @@
import java.util.List;
import java.util.Map;
import org.enso.interpreter.runtime.data.Type;
import org.enso.interpreter.test.ValuesGenerator;
import org.enso.interpreter.test.ValuesGenerator.Language;
import org.enso.test.utils.ContextUtils;
import org.graalvm.polyglot.Context;
Expand Down
Loading