From 737056174f7d01ba80ab6098cbaa32f9a941504a Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Tue, 27 Sep 2022 19:03:25 +0200 Subject: [PATCH] testscript: Fail testscript if txtar contains duplicate filenames --- .../testdata/testscript_duplicate_file.txt | 16 ++++++++++++++++ testscript/testscript.go | 3 +++ 2 files changed, 19 insertions(+) create mode 100644 testscript/testdata/testscript_duplicate_file.txt diff --git a/testscript/testdata/testscript_duplicate_file.txt b/testscript/testdata/testscript_duplicate_file.txt new file mode 100644 index 00000000..55501a07 --- /dev/null +++ b/testscript/testdata/testscript_duplicate_file.txt @@ -0,0 +1,16 @@ +# Check that duplicate filenames are detected. +unquote scripts-simple/testscript.txt +unquote scripts-normalized/testscript.txt + +! testscript scripts-simple +stdout 'duplicate filename' + +! testscript scripts-normalized +stdout 'duplicate filename' + +-- scripts-simple/testscript.txt -- +>-- file -- +>-- file -- +-- scripts-normalized/testscript.txt -- +>-- file -- +>-- dir/../file -- \ No newline at end of file diff --git a/testscript/testscript.go b/testscript/testscript.go index 2b0cd75e..d1890eb9 100644 --- a/testscript/testscript.go +++ b/testscript/testscript.go @@ -364,6 +364,9 @@ func (ts *TestScript) setup() string { ts.archive = a for _, f := range a.Files { name := ts.MkAbs(ts.expand(f.Name)) + if _, exists := ts.scriptFiles[name]; exists { + ts.Fatalf("%s: duplicate filename", f.Name) + } ts.scriptFiles[name] = f.Name ts.Check(os.MkdirAll(filepath.Dir(name), 0o777)) ts.Check(ioutil.WriteFile(name, f.Data, 0o666))