Skip to content

Commit 25a1f80

Browse files
committed
More DRY
Rather than following all `newBuilder` by `withLogHandler` ones, making the builder use `JulHandler` by default. This change required changes to `ExecCompilerTest` and `HelloWorldCacheTest` to make use of log messages rather than stdout.
1 parent 681ad5a commit 25a1f80

33 files changed

+157
-91
lines changed

engine/runtime-integration-tests/src/test/java/org/enso/compiler/test/BindingsMapResolutionTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111
import java.util.List;
1212
import java.util.Set;
1313
import java.util.function.Consumer;
14-
import java.util.logging.Level;
1514
import org.enso.common.RuntimeOptions;
1615
import org.enso.compiler.data.BindingsMap;
1716
import org.enso.compiler.data.BindingsMap.ResolutionError;
1817
import org.enso.compiler.data.BindingsMap.ResolvedConstructor;
1918
import org.enso.compiler.data.BindingsMap.ResolvedModule;
2019
import org.enso.compiler.data.BindingsMap.ResolvedName;
2120
import org.enso.compiler.data.BindingsMap.ResolvedType;
22-
import org.enso.logger.JulHandler;
2321
import org.enso.pkg.QualifiedName;
2422
import org.enso.polyglot.PolyglotContext;
2523
import org.enso.test.utils.ContextUtils;
2624
import org.enso.test.utils.ProjectUtils;
2725
import org.enso.test.utils.SourceModule;
26+
import org.enso.testkit.ReportLogsOnFailureRule;
2827
import org.junit.ClassRule;
2928
import org.junit.Ignore;
29+
import org.junit.Rule;
3030
import org.junit.Test;
3131
import org.junit.rules.TemporaryFolder;
3232
import scala.jdk.CollectionConverters;
@@ -36,6 +36,9 @@ public class BindingsMapResolutionTest {
3636

3737
@ClassRule public static final TemporaryFolder TMP_DIR = new TemporaryFolder();
3838

39+
@Rule(order = Integer.MIN_VALUE)
40+
public ReportLogsOnFailureRule appenderRule = new ReportLogsOnFailureRule();
41+
3942
@Test
4043
public void resolveSingleName_FromSingleImport() throws IOException {
4144
var projDir = createProject("import local.Proj.My_Vector.My_Vector");
@@ -641,7 +644,6 @@ private static ContextUtils createCtx(Path projDir) {
641644
return ContextUtils.newBuilder()
642645
.withModifiedContext(
643646
bldr -> bldr.option(RuntimeOptions.PROJECT_ROOT, projDir.toAbsolutePath().toString()))
644-
.withLogHandler(Level.FINE, JulHandler.get())
645647
.build();
646648
}
647649

engine/runtime-integration-tests/src/test/java/org/enso/compiler/test/ExecCompilerTest.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.enso.compiler.test;
22

3-
import static org.enso.compiler.test.ExecStrictCompilerTest.ctxRule;
43
import static org.hamcrest.MatcherAssert.assertThat;
54
import static org.hamcrest.Matchers.containsString;
65
import static org.junit.Assert.assertEquals;
@@ -15,25 +14,22 @@
1514
import org.enso.common.RuntimeOptions;
1615
import org.enso.compiler.core.ir.expression.errors.Conversion.DeclaredAsPrivate$;
1716
import org.enso.test.utils.ContextUtils;
17+
import org.enso.testkit.ReportLogsOnFailureRule;
1818
import org.graalvm.polyglot.PolyglotException;
1919
import org.graalvm.polyglot.Source;
2020
import org.hamcrest.core.AllOf;
21-
import org.junit.After;
22-
import org.junit.ClassRule;
23-
import org.junit.Ignore;
24-
import org.junit.Test;
21+
import org.junit.*;
2522

2623
public class ExecCompilerTest {
27-
/**
28-
* Not using JulHandler as a handler since some tests capture and verify reported errors in
29-
* strict-errors mode.
30-
*/
3124
@ClassRule
3225
public static final ContextUtils ctxRule =
3326
ContextUtils.newBuilder()
3427
.withModifiedContext(ctxBldr -> ctxBldr.option(RuntimeOptions.STRICT_ERRORS, "false"))
3528
.build();
3629

30+
@Rule(order = Integer.MIN_VALUE)
31+
public ReportLogsOnFailureRule appenderRule = new ReportLogsOnFailureRule();
32+
3733
@After
3834
public void cleanup() {
3935
ctxRule.resetOut();
@@ -532,7 +528,8 @@ public void illegalPrivateConversion() {
532528
var expectedErrMsg = DeclaredAsPrivate$.MODULE$.explain();
533529
var runMethod = module.invokeMember(Module.EVAL_EXPRESSION, "run");
534530
runMethod.execute(0);
535-
assertThat(ctxRule.getOut(), containsString(expectedErrMsg));
531+
assertTrue(
532+
appenderRule.pendingLogMessages().stream().anyMatch(e -> e.contains(expectedErrMsg)));
536533
}
537534

538535
@Test

engine/runtime-integration-tests/src/test/java/org/enso/compiler/test/ExecStrictCompilerTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
import static org.junit.Assert.assertTrue;
1111
import static org.junit.Assert.fail;
1212

13-
import java.util.logging.Level;
1413
import org.enso.common.LanguageInfo;
1514
import org.enso.common.MethodNames;
1615
import org.enso.common.RuntimeOptions;
17-
import org.enso.logger.JulHandler;
1816
import org.enso.test.utils.ContextUtils;
1917
import org.enso.testkit.ReportLogsOnFailureRule;
2018
import org.graalvm.polyglot.PolyglotException;
@@ -30,7 +28,6 @@ public class ExecStrictCompilerTest {
3028
public static final ContextUtils ctxRule =
3129
ContextUtils.newBuilder()
3230
.withModifiedContext(ctxBldr -> ctxBldr.option(RuntimeOptions.STRICT_ERRORS, "true"))
33-
.withLogHandler(Level.FINE, JulHandler.get())
3431
.build();
3532

3633
@Rule(order = Integer.MIN_VALUE)

engine/runtime-integration-tests/src/test/java/org/enso/compiler/test/ExportCycleDetectionTest.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import java.io.IOException;
1111
import java.nio.file.Path;
1212
import java.util.Set;
13-
import java.util.logging.Level;
14-
import org.enso.logger.JulHandler;
1513
import org.enso.pkg.QualifiedName;
1614
import org.enso.polyglot.PolyglotContext;
1715
import org.enso.test.utils.ContextUtils;
@@ -130,11 +128,7 @@ public void noCycleDetectedWhenExportingSymbolsFromItself_2() throws IOException
130128
private void expectNoCompilationErrors(Path projDir, String code) throws IOException {
131129
var mainMod = new SourceModule(QualifiedName.fromString("Main"), code);
132130
ProjectUtils.createProject("Proj", Set.of(mainMod), projDir);
133-
try (var ctx =
134-
ContextUtils.newBuilder()
135-
.withProjectRoot(projDir)
136-
.withLogHandler(Level.FINE, JulHandler.get())
137-
.build()) {
131+
try (var ctx = ContextUtils.newBuilder().withProjectRoot(projDir).build()) {
138132
var polyCtx = new PolyglotContext(ctx.context());
139133
try {
140134
polyCtx.getTopScope().compile(true);
@@ -148,11 +142,7 @@ private void expectNoCompilationErrors(Path projDir, String code) throws IOExcep
148142
}
149143

150144
private void expectProjectCompilationError(Path projDir, Matcher<String> errMsgMatcher) {
151-
try (var ctx =
152-
ContextUtils.newBuilder()
153-
.withProjectRoot(projDir)
154-
.withLogHandler(Level.FINE, JulHandler.get())
155-
.build()) {
145+
try (var ctx = ContextUtils.newBuilder().withProjectRoot(projDir).build()) {
156146
var polyCtx = new PolyglotContext(ctx.context());
157147
try {
158148
polyCtx.getTopScope().compile(true);

engine/runtime-integration-tests/src/test/java/org/enso/compiler/test/ExportedSymbolsTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
import java.util.List;
1414
import java.util.Map;
1515
import java.util.Set;
16-
import java.util.logging.Level;
1716
import org.enso.compiler.context.CompilerContext.Module;
1817
import org.enso.compiler.data.BindingsMap;
19-
import org.enso.logger.JulHandler;
2018
import org.enso.pkg.QualifiedName;
2119
import org.enso.polyglot.PolyglotContext;
2220
import org.enso.test.utils.ContextUtils;
@@ -233,10 +231,7 @@ public void exportSyntheticModule() throws IOException {
233231
}
234232

235233
private static ContextUtils createCtx(Path projDir) {
236-
return ContextUtils.newBuilder()
237-
.withProjectRoot(projDir)
238-
.withLogHandler(Level.FINE, JulHandler.get())
239-
.build();
234+
return ContextUtils.newBuilder().withProjectRoot(projDir).build();
240235
}
241236

242237
private static void compile(ContextUtils ctx) {

engine/runtime-integration-tests/src/test/java/org/enso/compiler/test/ImportsAndFQNConsistencyTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.util.ArrayList;
99
import java.util.Arrays;
1010
import java.util.List;
11-
import java.util.logging.Level;
1211
import java.util.stream.Collectors;
1312
import org.enso.common.RuntimeOptions;
1413
import org.enso.compiler.core.ir.module.scope.Definition;
@@ -17,7 +16,6 @@
1716
import org.enso.compiler.data.BindingsMap.ResolvedModule;
1817
import org.enso.compiler.data.BindingsMap.ResolvedType;
1918
import org.enso.interpreter.runtime.EnsoContext;
20-
import org.enso.logger.JulHandler;
2119
import org.enso.test.utils.ContextUtils;
2220
import org.enso.testkit.ReportLogsOnFailureRule;
2321
import org.junit.ClassRule;
@@ -48,7 +46,6 @@ public class ImportsAndFQNConsistencyTest {
4846
public static final ContextUtils ctxRule =
4947
ContextUtils.newBuilder()
5048
.withModifiedContext(ctxBldr -> ctxBldr.option(RuntimeOptions.DISABLE_IR_CACHES, "false"))
51-
.withLogHandler(Level.FINE, JulHandler.get())
5249
.build();
5350

5451
@Rule(order = Integer.MIN_VALUE)

engine/runtime-integration-tests/src/test/java/org/enso/compiler/test/WarningsAsErrorsTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import static org.junit.Assert.assertTrue;
55
import static org.junit.Assert.fail;
66

7-
import java.util.logging.Level;
87
import org.enso.common.RuntimeOptions;
9-
import org.enso.logger.JulHandler;
108
import org.enso.test.utils.ContextUtils;
119
import org.enso.testkit.ReportLogsOnFailureRule;
1210
import org.graalvm.polyglot.PolyglotException;
@@ -20,7 +18,6 @@ public class WarningsAsErrorsTest {
2018
ContextUtils.newBuilder()
2119
.withModifiedContext(
2220
ctxBldr -> ctxBldr.option(RuntimeOptions.TREAT_WARNINGS_AS_ERRORS, "true"))
23-
.withLogHandler(Level.FINE, JulHandler.get())
2421
.build();
2522

2623
@Rule(order = Integer.MIN_VALUE)

engine/runtime-integration-tests/src/test/java/org/enso/interpreter/caches/HelloWorldCacheTest.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
import java.util.stream.Collectors;
1111
import org.enso.common.RuntimeOptions;
1212
import org.enso.test.utils.ContextUtils;
13+
import org.enso.testkit.ReportLogsOnFailureRule;
1314
import org.graalvm.polyglot.Source;
15+
import org.junit.Rule;
1416
import org.junit.Test;
1517

1618
public class HelloWorldCacheTest {
1719

20+
@Rule(order = Integer.MIN_VALUE)
21+
public ReportLogsOnFailureRule appenderRule = new ReportLogsOnFailureRule();
22+
1823
@Test
1924
public void loadingHelloWorldTwiceUsesCaching() throws Exception {
2025
var root = new File("../..").getAbsoluteFile();
@@ -23,23 +28,24 @@ public void loadingHelloWorldTwiceUsesCaching() throws Exception {
2328
assertTrue("Hello_World.enso found", helloWorld.exists());
2429

2530
// the first run may or may not use caches
26-
var firstMsgs = executeOnce(helloWorld);
31+
var firstMsgs = executeOnce(helloWorld).stdout();
2732
assertTrue("Contains hello world:\n" + firstMsgs, firstMsgs.endsWith("Hello World"));
2833
// after the first run the caches for Hello_World.enso must be generated
2934

3035
// the second run must read Hello_World from its .ir file!
31-
var secondMsgs = executeOnce(helloWorld);
36+
var secondMsgsOutput = executeOnce(helloWorld);
37+
var secondMsgs = secondMsgsOutput.stdout();
3238
assertTrue("Contains hello world:\n" + secondMsgs, secondMsgs.contains("Hello World"));
3339
assertThat(
34-
"Properly deserialized:\n" + secondMsgs,
35-
secondMsgs,
40+
"Properly deserialized:\n" + secondMsgsOutput.logs(),
41+
secondMsgsOutput.logs(),
3642
allOf(
3743
containsString("Deserializing module"),
3844
containsString("Hello_World"),
3945
containsString("from IR file: true")));
4046
}
4147

42-
private static String executeOnce(File src) throws Exception {
48+
private OutputPair executeOnce(File src) throws Exception {
4349
try (var ctx =
4450
ContextUtils.newBuilder()
4551
.withModifiedContext(
@@ -52,13 +58,22 @@ private static String executeOnce(File src) throws Exception {
5258
var code = Source.newBuilder("enso", src).build();
5359
var res = ctx.evalModule(code, "main");
5460
assertTrue("Result of IO.println is Nothing", res.isNull());
55-
return ctx.getOut()
56-
.lines()
57-
.filter(l -> l.toUpperCase().contains("HELLO"))
58-
.collect(Collectors.joining("\n"));
61+
var result =
62+
new OutputPair(
63+
ctx.getOut()
64+
.lines()
65+
.filter(l -> l.toUpperCase().contains("HELLO"))
66+
.collect(Collectors.joining("\n")),
67+
appenderRule.pendingLogMessages().stream()
68+
.filter(l -> l.toUpperCase().contains("HELLO"))
69+
.collect(Collectors.joining("\n")));
70+
appenderRule.dropPendingMessages();
71+
return result;
5972
}
6073
}
6174

75+
private record OutputPair(String stdout, String logs) {}
76+
6277
private static File children(File f, String... names) {
6378
for (var n : names) {
6479
f = new File(f, n);

engine/runtime-integration-tests/src/test/java/org/enso/interpreter/caches/ModuleCacheTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
import static org.junit.Assert.assertTrue;
66

77
import java.nio.ByteBuffer;
8-
import java.util.logging.Level;
98
import org.enso.common.CompilationStage;
109
import org.enso.common.MethodNames;
1110
import org.enso.common.RuntimeOptions;
1211
import org.enso.compiler.test.CompilerTests;
13-
import org.enso.logger.JulHandler;
1412
import org.enso.test.utils.ContextUtils;
1513
import org.enso.testkit.ReportLogsOnFailureRule;
1614
import org.graalvm.polyglot.Source;
@@ -23,7 +21,6 @@ public class ModuleCacheTest {
2321
public static final ContextUtils ctxRule =
2422
ContextUtils.newBuilder()
2523
.withModifiedContext(ctxBldr -> ctxBldr.option(RuntimeOptions.DISABLE_IR_CACHES, "true"))
26-
.withLogHandler(Level.FINE, JulHandler.get())
2724
.build();
2825

2926
@Rule(order = Integer.MIN_VALUE)

engine/runtime-integration-tests/src/test/java/org/enso/interpreter/runtime/ModuleTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010

1111
import java.io.File;
1212
import java.io.IOException;
13-
import java.util.logging.Level;
1413
import org.enso.common.LanguageInfo;
1514
import org.enso.common.MethodNames;
1615
import org.enso.common.RuntimeOptions;
1716
import org.enso.compiler.data.BindingsMap;
1817
import org.enso.compiler.data.BindingsMap$ModuleReference$Concrete;
19-
import org.enso.logger.JulHandler;
2018
import org.enso.pkg.QualifiedName;
2119
import org.enso.test.utils.ContextUtils;
2220
import org.enso.testkit.ReportLogsOnFailureRule;
@@ -36,7 +34,6 @@ public class ModuleTest {
3634
public static final ContextUtils ctxRule =
3735
ContextUtils.newBuilder()
3836
.withModifiedContext(b -> b.option(RuntimeOptions.STRICT_ERRORS, "false"))
39-
.withLogHandler(Level.FINE, JulHandler.get())
4037
.build();
4138

4239
@Rule(order = Integer.MIN_VALUE)

0 commit comments

Comments
 (0)