From 1fe732f72df3920a3b82e74b95267ed8eaf4d416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Brachtha=CC=88user?= Date: Fri, 3 Jan 2025 13:32:38 +0100 Subject: [PATCH] Run no-valgrind tests, except those that segfault --- .../src/test/scala/effekt/EffektTests.scala | 50 ++++++++----------- .../test/scala/effekt/JavaScriptTests.scala | 2 +- .../jvm/src/test/scala/effekt/LLVMTests.scala | 17 +++++-- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/effekt/jvm/src/test/scala/effekt/EffektTests.scala b/effekt/jvm/src/test/scala/effekt/EffektTests.scala index d8de0ba1f..9c202f1f3 100644 --- a/effekt/jvm/src/test/scala/effekt/EffektTests.scala +++ b/effekt/jvm/src/test/scala/effekt/EffektTests.scala @@ -36,11 +36,6 @@ trait EffektTests extends munit.FunSuite { def negatives: List[File] = List() - def runTestFor(input: File, expected: String): Unit = - test(input.getPath + s" (${backendName})") { - assertNoDiff(run(input), expected) - } - // one shared driver for all tests in this test runner object driver extends effekt.Driver @@ -59,7 +54,7 @@ trait EffektTests extends munit.FunSuite { compiler.compileFile(input.getPath, configs) compiler.context.backup - def run(input: File): String = + def run(input: File, valgrind: Boolean, debug: Boolean): String = val compiler = driver var options = Seq( "--Koutput", "string", @@ -90,28 +85,28 @@ trait EffektTests extends munit.FunSuite { compiler.messaging.get.toList - def runTests() = + def runTests(valgrind: Boolean, debug: Boolean, ignored: List[File]) = Backend.backend(backendName).runner.checkSetup() match { case Left(msg) => test(s"${this.getClass.getName}: ${msg}".ignore) { () } case Right(value) => - negatives.foreach(runNegativeTestsIn) - positives.foreach(runPositiveTestsIn) + negatives.foreach(runNegativeTestsIn(valgrind, debug, ignored)) + positives.foreach(runPositiveTestsIn(valgrind, debug, ignored)) } - def runPositiveTestsIn(dir: File): Unit = - foreachFileIn(dir) { + def runPositiveTestsIn(valgrind: Boolean, debug: Boolean, ignored: List[File])(dir: File): Unit = + foreachFileIn(dir, ignored) { case (f, None) => sys error s"Missing checkfile for ${f.getPath}" case (f, Some(expected)) => test(s"${f.getPath} (${backendName})") { - assertNoDiff(run(f), expected) + assertNoDiff(run(f, valgrind, debug), expected) } } - def runNegativeTestsIn(dir: File): Unit = - foreachFileIn(dir) { + def runNegativeTestsIn(valgrind: Boolean, debug: Boolean, ignored: List[File])(dir: File): Unit = + foreachFileIn(dir, ignored) { case (f, Some(expected)) => test(s"${f.getPath} (${backendName})") { - assertNoDiff(run(f), expected) + assertNoDiff(run(f, valgrind, debug), expected) } case (f, None) => @@ -158,24 +153,23 @@ trait EffektTests extends munit.FunSuite { assert(messages.nonEmpty) - def foreachFileIn(file: File)(test: (File, Option[String]) => Unit): Unit = + def expectedResultFor(f: File): Option[String] = { + val path = f.getParentFile + val baseName = f.getName.stripSuffix(".md").stripSuffix(".effekt") + val checkfile = path / (baseName + ".check") + if checkfile.exists() then Some(IO.read(checkfile)) else None + } + + def foreachFileIn(file: File, ignored: List[File])(test: (File, Option[String]) => Unit): Unit = file match { case f if f.isDirectory && !ignored.contains(f) => - f.listFiles.foreach(foreachFileIn(_)(test)) + f.listFiles.foreach(f => foreachFileIn(f, ignored)(test)) case f if f.getName.endsWith(".effekt") || f.getName.endsWith(".effekt.md") => - val path = f.getParentFile - val baseName = f.getName.stripSuffix(".md").stripSuffix(".effekt") - - if (ignored.contains(f)) { - ignored.contains(f) - } else { - val checkfile = path / (baseName + ".check") - val expected = if checkfile.exists() then Some(IO.read(checkfile)) else None - - test(f, expected) + if (!ignored.contains(f)) { + test(f, expectedResultFor(f)) } case _ => () } - runTests() + runTests(valgrind, debug, ignored) } diff --git a/effekt/jvm/src/test/scala/effekt/JavaScriptTests.scala b/effekt/jvm/src/test/scala/effekt/JavaScriptTests.scala index c3626213d..608e35069 100644 --- a/effekt/jvm/src/test/scala/effekt/JavaScriptTests.scala +++ b/effekt/jvm/src/test/scala/effekt/JavaScriptTests.scala @@ -58,7 +58,7 @@ object TestUtils { val shouldGenerate = regenerateAll || f.lastModified() > checkfile.lastModified() if (!isIgnored && shouldGenerate) { println(s"Writing checkfile for ${f}") - val out = run(f) + val out = run(f, valgrind, debug) // Save checkfile in source folder (e.g. examples/) // We remove ansi colors to make check files human-readable. diff --git a/effekt/jvm/src/test/scala/effekt/LLVMTests.scala b/effekt/jvm/src/test/scala/effekt/LLVMTests.scala index a65046cd0..3c49e98c6 100644 --- a/effekt/jvm/src/test/scala/effekt/LLVMTests.scala +++ b/effekt/jvm/src/test/scala/effekt/LLVMTests.scala @@ -23,6 +23,14 @@ class LLVMTests extends EffektTests { // names not sanitized (even?) examplesDir / "pos" / "special_names.effekt", + // segfault + examplesDir / "benchmarks" / "input_output" / "word_count_ascii.effekt", + examplesDir / "benchmarks" / "input_output" / "word_count_utf8.effekt", + examplesDir / "benchmarks" / "input_output" / "dyck_one.effekt", + examplesDir / "benchmarks" / "input_output" / "number_matrix.effekt", + ) + + lazy val noValgrind: List[File] = List( // sanitizer/valgrind: segfault examplesDir / "pos" / "parametrized.effekt", @@ -37,10 +45,6 @@ class LLVMTests extends EffektTests { examplesDir / "benchmarks" / "are_we_fast_yet" / "towers.effekt", examplesDir / "benchmarks" / "are_we_fast_yet" / "permute.effekt", examplesDir / "benchmarks" / "are_we_fast_yet" / "queens.effekt", - examplesDir / "benchmarks" / "input_output" / "word_count_ascii.effekt", - examplesDir / "benchmarks" / "input_output" / "word_count_utf8.effekt", - examplesDir / "benchmarks" / "input_output" / "dyck_one.effekt", - examplesDir / "benchmarks" / "input_output" / "number_matrix.effekt", ) /** @@ -101,5 +105,8 @@ class LLVMTests extends EffektTests { examplesDir / "pos" / "issue733.effekt", ) - override lazy val ignored: List[File] = bugs ++ missingFeatures + override lazy val ignored: List[File] = bugs ++ missingFeatures ++ noValgrind + + // Also run the no-valgrind tests with valgrind disabled. + noValgrind.foreach(runPositiveTestsIn(valgrind = false, debug = debug, ignored = Nil)) }