make bincmp keep binaries around when it fails

Even if diffoscope is installed, because further investigation might be
needed, and some failures are rare or hard to reproduce.

Make GitHub Actions upload those artifacts,
so that a failed CI run on Windows or Mac due to bincmp
allows us to download and inspect those binaries locally.
pull/611/head
Daniel Martí 1 year ago
parent e61317e7ae
commit 12bc0349e6

@ -32,6 +32,11 @@ jobs:
- uses: actions/checkout@v3
- name: Test
run: go test -timeout=15m ./...
- uses: actions/upload-artifact@v3
if: failure()
with:
name: bincmp_output
path: bincmp_output/
- name: Test with -race
# macos and windows tend to be a bit slower,
# and it's rare that a race in garble would be OS-specific.

3
.gitignore vendored

@ -1,2 +1,3 @@
/garble
/test
/test
/bincmp_output/

@ -196,15 +196,34 @@ func bincmp(ts *testscript.TestScript, neg bool, args []string) {
return
}
if data1 != data2 {
if _, err := exec.LookPath("diffoscope"); err != nil {
ts.Logf("diffoscope is not installing; skipping binary diff")
} else {
if _, err := exec.LookPath("diffoscope"); err == nil {
// We'll error below; ignore the exec error here.
ts.Exec("diffoscope",
"--diff-context", "2", // down from 7 by default
"--max-text-report-size", "4096", // no limit (in bytes) by default; avoid huge output
ts.MkAbs(args[0]), ts.MkAbs(args[1]))
} else {
ts.Logf("diffoscope not found; skipping")
}
outDir := "bincmp_output"
err := os.MkdirAll(outDir, 0o777)
ts.Check(err)
file1, err := os.CreateTemp(outDir, "file1-*")
ts.Check(err)
_, err = file1.Write([]byte(data1))
ts.Check(err)
err = file1.Close()
ts.Check(err)
file2, err := os.CreateTemp(outDir, "file2-*")
ts.Check(err)
_, err = file2.Write([]byte(data2))
ts.Check(err)
err = file2.Close()
ts.Check(err)
ts.Logf("wrote files to %s and %s", file1.Name(), file2.Name())
sizeDiff := len(data2) - len(data1)
ts.Fatalf("%s and %s differ; diffoscope above, size diff: %+d",
args[0], args[1], sizeDiff)

Loading…
Cancel
Save