Skip to content

Commit e84fa37

Browse files
committed
testscript: protect against no-op uses of cmp
This just bit me and it stumped me for a solid five minutes. I'm sure I've made the mistake at least one more time elsewhere.
1 parent ee70938 commit e84fa37

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

testscript/cmd.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ func (ts *TestScript) cmdCmpenv(neg bool, args []string) {
111111

112112
func (ts *TestScript) doCmdCmp(neg bool, args []string, env bool) {
113113
name1, name2 := args[0], args[1]
114+
if name1 == name2 {
115+
// It's surprisingly easy to do e.g. `cmp foo.go foo.go` rather than
116+
// `cmp foo.go foo.go.want`; protect against such obvious cases.
117+
ts.Fatalf("cmp: comparing the same file twice")
118+
}
114119
text1 := ts.ReadFile(name1)
115120

116121
absName2 := ts.MkAbs(name2)

0 commit comments

Comments
 (0)