Tests can now compile dependencies first
This commit is contained in:
parent
785a77b21b
commit
cc2b1315a0
@ -13,6 +13,52 @@ import "git.tebibyte.media/fspl/fspl/testcommon"
|
|||||||
//go:embed all:test-data/*
|
//go:embed all:test-data/*
|
||||||
var testData embed.FS
|
var testData embed.FS
|
||||||
|
|
||||||
|
func defaultCompiler () *Compiler {
|
||||||
|
// instantiate and configure the compiler
|
||||||
|
comp := new(Compiler)
|
||||||
|
comp.Prefix = "compiler"
|
||||||
|
comp.Resolver = NewResolver (
|
||||||
|
"/test-data/usr/local/src/fspl",
|
||||||
|
"/test-data/usr/src/fspl",
|
||||||
|
"/test-data/usr/local/incude/fspl",
|
||||||
|
"/test-data/usr/include/fspl")
|
||||||
|
comp.Resolver.FS = testData
|
||||||
|
comp.Format = ".o"
|
||||||
|
comp.Debug = true
|
||||||
|
return comp
|
||||||
|
}
|
||||||
|
|
||||||
|
func compileDependency (
|
||||||
|
test *testing.T,
|
||||||
|
address entity.Address,
|
||||||
|
) string {
|
||||||
|
// create temporary directory
|
||||||
|
temp := test.TempDir()
|
||||||
|
|
||||||
|
// instantiate and configure the compiler
|
||||||
|
compOutputBuilder := new(strings.Builder)
|
||||||
|
comp := defaultCompiler()
|
||||||
|
defer func () {
|
||||||
|
test.Logf (
|
||||||
|
"compiler log for dependency %s:\n%s",
|
||||||
|
address, compOutputBuilder)
|
||||||
|
} ()
|
||||||
|
comp.Writer = compOutputBuilder
|
||||||
|
nickname, ok := address.Nickname()
|
||||||
|
if !ok {
|
||||||
|
test.Fatal("could not generate nickname for", address)
|
||||||
|
}
|
||||||
|
comp.Output = filepath.Join(temp, nickname)
|
||||||
|
|
||||||
|
// compile to object file
|
||||||
|
err := comp.CompileUnit(address)
|
||||||
|
if err != nil {
|
||||||
|
test.Fatal("compiler returned error:", errors.Format(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return comp.Output
|
||||||
|
}
|
||||||
|
|
||||||
func testUnit (
|
func testUnit (
|
||||||
test *testing.T,
|
test *testing.T,
|
||||||
address entity.Address,
|
address entity.Address,
|
||||||
@ -26,27 +72,18 @@ func testUnit (
|
|||||||
|
|
||||||
// instantiate and configure the compiler
|
// instantiate and configure the compiler
|
||||||
compOutputBuilder := new(strings.Builder)
|
compOutputBuilder := new(strings.Builder)
|
||||||
|
comp := defaultCompiler()
|
||||||
defer func () {
|
defer func () {
|
||||||
test.Log("compiler log:\n" + compOutputBuilder.String())
|
test.Log("compiler log:\n" + compOutputBuilder.String())
|
||||||
} ()
|
} ()
|
||||||
comp := new(Compiler)
|
|
||||||
comp.Writer = compOutputBuilder
|
comp.Writer = compOutputBuilder
|
||||||
comp.Prefix = "compiler"
|
|
||||||
comp.Resolver = NewResolver (
|
|
||||||
"/test-data/usr/local/src/fspl",
|
|
||||||
"/test-data/usr/src/fspl",
|
|
||||||
"/test-data/usr/local/incude/fspl",
|
|
||||||
"/test-data/usr/include/fspl")
|
|
||||||
comp.Resolver.FS = testData
|
|
||||||
comp.Output = filepath.Join(temp, "output.o")
|
comp.Output = filepath.Join(temp, "output.o")
|
||||||
comp.Format = ".o"
|
|
||||||
comp.Debug = true
|
|
||||||
|
|
||||||
// compile to object file
|
// compile to object file
|
||||||
err := comp.CompileUnit(address)
|
err := comp.CompileUnit(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
test.Error("compiler returned error:", errors.Format(err))
|
test.Fatal("compiler returned error:", errors.Format(err))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// link the object file into an executable
|
// link the object file into an executable
|
||||||
@ -61,8 +98,7 @@ func testUnit (
|
|||||||
test.Log("running link command: ", linkCommand)
|
test.Log("running link command: ", linkCommand)
|
||||||
err = linkCommand.Run()
|
err = linkCommand.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
test.Error("error linking executable:", err)
|
test.Fatal("error linking executable:", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// run the executable file and check its output
|
// run the executable file and check its output
|
||||||
@ -82,8 +118,7 @@ func testUnit (
|
|||||||
exit, code)
|
exit, code)
|
||||||
}
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
test.Errorf("error running %s: %v", executablePath, err)
|
test.Fatalf("error running %s: %v", executablePath, err)
|
||||||
return
|
|
||||||
} else {
|
} else {
|
||||||
if 0 != exit {
|
if 0 != exit {
|
||||||
test.Errorf("expecting exit code %d, got 0", exit)
|
test.Errorf("expecting exit code %d, got 0", exit)
|
||||||
@ -94,6 +129,7 @@ func testUnit (
|
|||||||
gotStdout := stdoutBuilder.String()
|
gotStdout := stdoutBuilder.String()
|
||||||
if gotStdout != stdout {
|
if gotStdout != stdout {
|
||||||
testcommon.CompareHex(test, stdout, gotStdout)
|
testcommon.CompareHex(test, stdout, gotStdout)
|
||||||
|
test.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user