Skip to content

Commit 9181448

Browse files
leitzlermyitcv
authored andcommitted
testscript: ensure that temp dir isn't sym-linked (#79)
In cases where ioutil.TempDir() returns a symbolic link (default behaviour in macOS) the workdir substitution could mess up output matching for programs that uses the real dir. This PR introduces sym-link evaluation of the test temp dir to ensure consistency.
1 parent 0483ff7 commit 9181448

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# If ioutil.TempDir returns a sym linked dir (default behaviour in macOS for example) the
2+
# matcher will have problems with external programs that uses the real path.
3+
# This script tests that $WORK is matched in a consistent way (also see #79).
4+
[windows] skip
5+
exec pwd
6+
stdout ^$WORK$
7+
exec pwd -P
8+
stdout ^$WORK$

testscript/testscript.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ func RunT(t T, p Params) {
150150
if err != nil {
151151
t.Fatal(err)
152152
}
153+
// The temp dir returned by ioutil.TempDir might be a sym linked dir (default
154+
// behaviour in macOS). That could mess up matching that includes $WORK if,
155+
// for example, an external program outputs resolved paths. Evaluating the
156+
// dir here will ensure consistency.
157+
testTempDir, err = filepath.EvalSymlinks(testTempDir)
158+
if err != nil {
159+
t.Fatal(err)
160+
}
153161
refCount := int32(len(files))
154162
for _, file := range files {
155163
file := file

0 commit comments

Comments
 (0)