Skip to content

Commit

Permalink
make bincmp keep binaries around when it fails
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mvdan committed Nov 13, 2022
1 parent e61317e commit 12bc034
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/garble
/test
/test
/bincmp_output/
25 changes: 22 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 12bc034

Please sign in to comment.