This commit is contained in:
Sasha Koshka
2024-03-20 13:29:26 -04:00
parent d6b2abf98f
commit a0496d3fab
+7 -5
View File
@@ -75,9 +75,9 @@ func testUnit (
// instantiate and configure the compiler
compOutputBuilder := new(strings.Builder)
comp := defaultCompiler()
defer func () {
outputCompilerLog := func () {
test.Log("COMPILER LOG (main unit):\n" + compOutputBuilder.String())
} ()
}
comp.Writer = compOutputBuilder
comp.Output = filepath.Join(temp, "output.o")
@@ -85,8 +85,10 @@ func testUnit (
// compile to object file
err := comp.CompileUnit(address)
if err != nil {
outputCompilerLog()
test.Fatal("compiler returned error:", errors.Format(err))
}
outputCompilerLog()
// link the object file into an executable
executablePath := filepath.Join(temp, "output")
@@ -104,7 +106,8 @@ func testUnit (
}
// run the executable file (with timeout) and check its output
ctx, cancel := context.WithTimeout(context.Background(), 2 * time.Second)
timeoutDuration := 10 * time.Millisecond
ctx, cancel := context.WithTimeout(context.Background(), timeoutDuration)
defer cancel()
executableCommand := exec.CommandContext(ctx, executablePath, args...)
stdoutBuilder := new(strings.Builder)
@@ -114,8 +117,7 @@ func testUnit (
err = executableCommand.Run()
if ctx.Err() == context.DeadlineExceeded {
test.Error("timeout exceeded!")
return
test.Errorf("timeout of %v exceeded!", timeoutDuration)
}
// check error, compare exit code