From 12bc0349e60cb112b0fbc1cdad2522b5660fd936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 13 Nov 2022 13:45:16 +0000 Subject: [PATCH] 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. --- .github/workflows/test.yml | 5 +++++ .gitignore | 3 ++- main_test.go | 25 ++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d08f65d..badad33 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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. diff --git a/.gitignore b/.gitignore index 3a3e340..dc5a973 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /garble -/test \ No newline at end of file +/test +/bincmp_output/ diff --git a/main_test.go b/main_test.go index e04f261..0a001ed 100644 --- a/main_test.go +++ b/main_test.go @@ -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)