diff --git a/engine/runtime/src/bench/java/org/enso/interpreter/bench/benchmarks/semantic/WarningBenchmarks.java b/engine/runtime/src/bench/java/org/enso/interpreter/bench/benchmarks/semantic/WarningBenchmarks.java index 22c01a9b00bc3..09c44b492f6cd 100644 --- a/engine/runtime/src/bench/java/org/enso/interpreter/bench/benchmarks/semantic/WarningBenchmarks.java +++ b/engine/runtime/src/bench/java/org/enso/interpreter/bench/benchmarks/semantic/WarningBenchmarks.java @@ -37,6 +37,7 @@ public class WarningBenchmarks extends TestBase { private Value elemWithWarning; private OutputStream out = new ByteArrayOutputStream(); + private String benchmarkName; @Setup public void initializeBench(BenchmarkParams params) throws IOException { @@ -55,6 +56,8 @@ public void initializeBench(BenchmarkParams params) throws IOException { .option("engine.BackgroundCompilation", "true") .build(); + benchmarkName = params.getBenchmark().replaceFirst(".*\\.", ""); + var code = """ from Standard.Base import all @@ -72,12 +75,7 @@ public void initializeBench(BenchmarkParams params) throws IOException { x = 42 Warning.attach "Foo!" x """; - - var file = File.createTempFile("warnings", ".enso"); - try (var w = new FileWriter(file)) { - w.write(code); - } - var src = Source.newBuilder("enso", file).build(); + var src = SrcUtil.source(benchmarkName, code); Value module = ctx.eval(src); vecSumBench = Objects.requireNonNull(module.invokeMember(MethodNames.Module.EVAL_EXPRESSION, "vec_sum_bench")); createVec = Objects.requireNonNull(module.invokeMember(MethodNames.Module.EVAL_EXPRESSION, "create_vec")); @@ -87,6 +85,11 @@ public void initializeBench(BenchmarkParams params) throws IOException { sameWarningVec = createVec.execute(INPUT_VEC_SIZE, elemWithWarning); } + @TearDown + public void cleanup() { + ctx.close(true); + } + @Benchmark public void noWarningsVecSum() { Value res = vecSumBench.execute(noWarningsVec); diff --git a/test/Tests/src/Semantic/Warnings_Spec.enso b/test/Tests/src/Semantic/Warnings_Spec.enso index 71260a2894b20..2d399139c5b67 100644 --- a/test/Tests/src/Semantic/Warnings_Spec.enso +++ b/test/Tests/src/Semantic/Warnings_Spec.enso @@ -19,6 +19,8 @@ My_Type.my_method self = self.a + self.b + self.c type Wrap Value foo +f x _ = Warning.attach "Baz!" x + type My_Fancy_Collection Value (x:Integer) @@ -403,4 +405,7 @@ spec = Test.group "Dataflow Warnings" <| result_3 = b + b + d Warning.get_all result_3 . map (x-> x.value.to_text) . should_equal ["Foo!", "Foo!"] + result_4 = f a 1 + f a 2 + f a 3 + Warning.get_all result_4 . map (x-> x.value.to_text) . should_equal ["Baz!", "Baz!", "Baz!"] + main = Test_Suite.run_main spec