From ca933d746ba16ef326d9b4ba85d51940ab9e8add Mon Sep 17 00:00:00 2001 From: Terin Stock Date: Sun, 29 Jul 2018 19:37:27 +0000 Subject: feat: initial version of midifi software This CL introduces the initial version of the midifi software, via a simplified CLI interface "playsmf". Though it is far from complete, this version can be manually invoked with the locations of the MIDI communications port (the `-com` flag), and MIDI file. It will playback the MIDI file with the correct time. Software is currently tested with an integration test, that invokes the program with a known MIDI file and compares the output of the serial port, standard out, and standard error. Golden files can be updated by providing the `-test.update-golden` flag. Change-Id: I312bc721736e2edf385ece5141133ffa6bd20a72 Signed-off-by: Terin Stock --- cmd/playsmf/main_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 cmd/playsmf/main_test.go (limited to 'cmd/playsmf/main_test.go') diff --git a/cmd/playsmf/main_test.go b/cmd/playsmf/main_test.go new file mode 100644 index 0000000..68ee28f --- /dev/null +++ b/cmd/playsmf/main_test.go @@ -0,0 +1,48 @@ +package main + +import ( + "fmt" + "io/ioutil" + "os" + "os/exec" + "testing" + + "github.com/pkg/term/termios" + "gotest.tools/golden" +) + +func TestMain(m *testing.M) { + switch os.Getenv("GOTESTMODE") { + case "main": + // run the normal main function + main() + default: + os.Exit(m.Run()) + } +} + +func TestCLI(t *testing.T) { + pty, tty, err := termios.Pty() + if err != nil { + t.Fatal(err) + } + defer pty.Close() + + cmd := exec.Command(os.Args[0], "-com", tty.Name(), "./testdata/ceottk.mid") + cmd.Env = append(os.Environ(), "GOTESTMODE=main") + + output, err := cmd.Output() + if err != nil { + fmt.Printf("output: %s\n", string(output)) + t.Fatal(err) + } + + tty.Close() + b, err := ioutil.ReadAll(pty) + if err != nil && err.Error() != "read ptm: input/output error" { + t.Errorf("error reading pty: %+v", err) + } + + golden.AssertBytes(t, b, "ceottk-serial.golden.bin") + golden.Assert(t, string(output), "ceottk-output.golden") +} -- cgit v1.2.3