I want to test, that a function callProgram
executes a binary and handles the output correctly.
For that my initial thought would be to compile raw code like:
package mytest
import (
"testing"
)
const (
binary_code = `
package main
func main() {
// Glorious processing ...
}
`
)
func TestCall(t *testing.T) {
p := buildTestProgram(binary_code, "~/testbinary")
defer p.Delete()
callProgram("~/testbinary")
}
I looked into the build command (runBuild
) and its' implementation is sufficiently easy. Problem is, that it lives in the internal
namespace and cmd/go
does not seem to expose any way of calling runBuild
or similar.
So my question is how to test a certain binary and also having to interact with the hosting system as little as possible.
Yes, I could download a prebuilt binary, execute go build
, etc. but I would be really glad to minimize the chances of potential errors/complexity and also be as portable as possible.