Skip to content

Commit

Permalink
Add test for private ctor call when private check is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Akirathan committed May 22, 2024
1 parent d7c1d96 commit 023eea5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.enso.polyglot.PolyglotContext;
import org.enso.polyglot.RuntimeOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Context.Builder;
import org.graalvm.polyglot.Language;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.Value;
Expand Down Expand Up @@ -227,14 +228,16 @@ protected static Path createProject(
* Tests running the project located in the given {@code projDir}. Is equal to running {@code enso
* --run <projDir>}.
*
* @param ctxBuilder A context builder that might be initialized with some specific options.
* @param projDir Root directory of the project.
* @param resultConsumer Any action that is to be evaluated on the result of running the {@code
* main} method
*/
protected void testProjectRun(Path projDir, Consumer<Value> resultConsumer) {
protected void testProjectRun(
Context.Builder ctxBuilder, Path projDir, Consumer<Value> resultConsumer) {
assert projDir.toFile().exists() && projDir.toFile().isDirectory();
try (var ctx =
defaultContextBuilder()
ctxBuilder
.option(RuntimeOptions.PROJECT_ROOT, projDir.toAbsolutePath().toString())
.option(RuntimeOptions.STRICT_ERRORS, "true")
.option(RuntimeOptions.DISABLE_IR_CACHES, "true")
Expand All @@ -249,6 +252,17 @@ protected void testProjectRun(Path projDir, Consumer<Value> resultConsumer) {
}
}

/**
* Just a wrapper for {@link TestBase#testProjectRun(Builder, Path, Consumer)}.
*
* @param projDir Root directory of the project.
* @param resultConsumer Any action that is to be evaluated on the result of running the {@code
* main} method
*/
protected void testProjectRun(Path projDir, Consumer<Value> resultConsumer) {
testProjectRun(defaultContextBuilder(), projDir, resultConsumer);
}

/** A simple structure corresponding to an Enso module. */
public record SourceModule(QualifiedName name, String code) {}

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

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import java.io.IOException;
import org.enso.interpreter.test.TestBase;
import org.enso.polyglot.RuntimeOptions;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

public class PrivateCheckDisabledTest extends TestBase {
@Rule public TemporaryFolder tempFolder = new TemporaryFolder();

@Test
public void privateCtorCanBeAccessedWhenPrivateCheckIsDisabled() throws IOException {
var libSrc = """
type T
private Cons data
""";
createProject("Lib", libSrc, tempFolder);
var mainSrc =
"""
from local.Lib import T
main =
obj = T.Cons 42
obj.data
""";
var mainDir = createProject("Main", mainSrc, tempFolder);
var ctxBuilder = defaultContextBuilder().option(RuntimeOptions.DISABLE_PRIVATE_CHECK, "true");
testProjectRun(
ctxBuilder,
mainDir,
res -> {
assertThat(res.isNumber(), is(true));
assertThat(res.asInt(), is(42));
});
}
}

0 comments on commit 023eea5

Please sign in to comment.