From 22e7e4e848b2e16296b8105ee62eafaa022e2200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 9 Dec 2019 13:00:27 +0000 Subject: [PATCH] add a bincmp builtin test command To be used soon for reproducible builds. --- main_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main_test.go b/main_test.go index 27f352d..f199601 100644 --- a/main_test.go +++ b/main_test.go @@ -62,6 +62,7 @@ func TestScripts(t *testing.T) { }, Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){ "bingrep": bingrep, + "bincmp": bincmp, }, UpdateScripts: *update, }) @@ -83,3 +84,18 @@ func bingrep(ts *testscript.TestScript, neg bool, args []string) { } } } + +func bincmp(ts *testscript.TestScript, neg bool, args []string) { + if neg { + ts.Fatalf("unsupported: ! bincmp") + } + if len(args) != 2 { + ts.Fatalf("usage: bincmp file1 file2") + } + data1 := ts.ReadFile(args[0]) + data2 := ts.ReadFile(args[1]) + if data1 != data2 { + sizeDiff := len(data2) - len(data1) + ts.Fatalf("%s and %s differ; size diff: %+d", args[0], args[1], sizeDiff) + } +}