package org.shedlang.compiler.backends.llvm; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; import org.shedlang.compiler.ShedCompiler; import org.shedlang.compiler.backends.ExampleSet; import org.shedlang.compiler.testing.TestProcessRunner; import java.io.IOException; import java.util.List; import java.util.Optional; import java.util.stream.Stream; public class Amd64ValgrindExampleTests { @TestFactory public Stream tests() { return ExampleSet.exampleSets() .map(exampleSet -> DynamicTest.dynamicTest( exampleSet.name(), () -> runTest(exampleSet) )); } private void runTest(ExampleSet exampleSet) throws IOException, InterruptedException { var config = exampleSet.readConfig(); for (var example : config.examples()) { if (example.expectedError().isEmpty()) { var compiler = new ShedCompiler(); var targetDir = compiler.compile( example.projectPath(), LlvmBackend.AMD64, Optional.empty() ); var binPath = targetDir.topLevel(example.bin()) .toString(); var leakExitCode = 127; var result = TestProcessRunner.runCaptureOutput(List.of( "valgrind", "--leak-check=full", "--error-exitcode=" + leakExitCode, binPath )); if (result.exitCode() == leakExitCode) { Assumptions.abort("Example had leaks:\n" + result.stderr()); } } } } }