File tree Expand file tree Collapse file tree 1 file changed +22
-5
lines changed Expand file tree Collapse file tree 1 file changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -82,10 +82,27 @@ func TestTxtar(t *testing.T) {
8282 testPrefix = "test: "
8383 wantPrefix = "want: "
8484 )
85+ var (
86+ join func (name string ) (tempPath string )
87+ chTmpDir func ()
88+ )
89+ {
90+ tmpPath := t .TempDir ()
91+ join = func (name string ) (tempPath string ) {
92+ return filepath .Join (tmpPath , name )
93+ }
94+ chTmpDir = func () { os .Chdir (tmpPath ) }
8595
86- tmpPath := t .TempDir ()
87- join := func (name string ) (tempPath string ) {
88- return filepath .Join (tmpPath , name )
96+ cwd , err := os .Getwd ()
97+ if err != nil {
98+ t .Fatalf ("could not get working dir: %v" , err )
99+ }
100+ t .Cleanup (func () {
101+ err := os .Chdir (cwd )
102+ if err != nil {
103+ t .Fatalf ("could not change back to orignal working dir %s: %v" , cwd , err )
104+ }
105+ })
89106 }
90107
91108 a , err := txtar .ParseFile ("./testdata/sql.txt" )
@@ -112,6 +129,8 @@ func TestTxtar(t *testing.T) {
112129 }
113130 }
114131
132+ chTmpDir ()
133+
115134 for i := 0 ; i < len (testPairs ); i += 2 {
116135 testFile := testPairs [i ]
117136 wantFile := testPairs [i + 1 ]
@@ -144,8 +163,6 @@ func TestTxtar(t *testing.T) {
144163 t .Fatalf ("could not parse args: %v" , err )
145164 }
146165
147- os .Chdir (tmpPath )
148-
149166 buf := bytes.Buffer {}
150167
151168 inputCsvs := GetInputCsvsOrPanic (fs .Args (), - 1 )
You can’t perform that action at this time.
0 commit comments