Skip to content

Commit

Permalink
testscript: Fail testscript if txtar contains duplicate filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Sep 27, 2022
1 parent 7a6a5f8 commit 7370561
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions testscript/testdata/testscript_duplicate_file.txt
Original file line number Diff line number Diff line change
@@ -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 --
3 changes: 3 additions & 0 deletions testscript/testscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 7370561

Please sign in to comment.