@@ -46,6 +46,15 @@ func writeTestFile(t *testing.T, path, content string) {
4646 }
4747}
4848
49+ func canonicalTestPath (t * testing.T , path string ) string {
50+ t .Helper ()
51+ path , err := filepath .EvalSymlinks (path )
52+ if err != nil {
53+ t .Fatal (err )
54+ }
55+ return path
56+ }
57+
4958func captureStdout (t * testing.T , fn func () (int , error )) (string , int , error ) {
5059 t .Helper ()
5160 r , w , err := os .Pipe ()
@@ -112,6 +121,11 @@ func TestCmdFmtImportsOverwrite(t *testing.T) {
112121 if err != nil {
113122 t .Fatal (err )
114123 }
124+ // Windows loads FileInfo IDs lazily when SameFile is first called. Prime
125+ // them before replacement so these values continue to identify the old files.
126+ if ! os .SameFile (rootInfoBefore , rootInfoBefore ) || ! os .SameFile (importedInfoBefore , importedInfoBefore ) {
127+ t .Fatal ("could not snapshot file identity" )
128+ }
115129
116130 fl := newFmtFlags (rootPath , true , false , true )
117131 code , err := cmdFmt (fl )
@@ -175,7 +189,7 @@ func TestCmdFmtImportsPreviewReportsFormattingDifference(t *testing.T) {
175189 if code != caddy .ExitCodeFailedStartup {
176190 t .Errorf ("expected ExitCodeFailedStartup, got %d" , code )
177191 }
178- if ! strings .Contains (output , "# " + importedPath ) {
192+ if ! strings .Contains (output , "# " + canonicalTestPath ( t , importedPath ) ) {
179193 t .Errorf ("output missing imported file header; got:\n %s" , output )
180194 }
181195 if diff && ! strings .Contains (output , "+ \t respond 200" ) {
@@ -257,10 +271,10 @@ func TestCmdFmtImportsPrintsHeaders(t *testing.T) {
257271 if code != caddy .ExitCodeSuccess {
258272 t .Errorf ("expected ExitCodeSuccess, got %d" , code )
259273 }
260- if ! strings .Contains (output , "# " + rootPath ) {
274+ if ! strings .Contains (output , "# " + canonicalTestPath ( t , rootPath ) ) {
261275 t .Errorf ("output missing root header; got:\n %s" , output )
262276 }
263- if ! strings .Contains (output , "# " + importedPath ) {
277+ if ! strings .Contains (output , "# " + canonicalTestPath ( t , importedPath ) ) {
264278 t .Errorf ("output missing imported file header; got:\n %s" , output )
265279 }
266280}
0 commit comments