@@ -170,6 +170,30 @@ func setupInitialFiles(t *testing.T, srcDir, targetDir string) {
170170 }
171171}
172172
173+ // normalizeLineEndings converts all line endings to LF (\n) for consistent comparison across platforms
174+ func normalizeLineEndings (data []byte ) []byte {
175+ return bytes .ReplaceAll (data , []byte ("\r \n " ), []byte ("\n " ))
176+ }
177+
178+ // normalizeErrorString normalizes error strings for cross-platform comparison by:
179+ // 1. Converting CRLF to LF
180+ // 2. Trimming trailing whitespace from each line
181+ // 3. Trimming leading/trailing whitespace from the entire string
182+ func normalizeErrorString (s string ) string {
183+ // Convert CRLF to LF
184+ s = strings .ReplaceAll (s , "\r \n " , "\n " )
185+
186+ // Split into lines, trim trailing spaces from each line, then rejoin
187+ lines := strings .Split (s , "\n " )
188+ for i , line := range lines {
189+ lines [i ] = strings .TrimRight (line , " \t " )
190+ }
191+ s = strings .Join (lines , "\n " )
192+
193+ // Trim leading/trailing whitespace from the entire string
194+ return strings .TrimSpace (s )
195+ }
196+
173197func assertSameFile (t * testing.T , file string , expectedFile string , overwriteExpected bool ) {
174198 if overwriteExpected && fileExists (file ) {
175199 assert .NoErr (t , CopyFile (file , expectedFile , 0 ))
@@ -190,6 +214,10 @@ func assertSameFile(t *testing.T, file string, expectedFile string, overwriteExp
190214 contentExpected , err := ioutil .ReadFile (expectedFile )
191215 assert .NoErr (t , err )
192216
217+ // Normalize line endings for cross-platform comparison
218+ content = normalizeLineEndings (content )
219+ contentExpected = normalizeLineEndings (contentExpected )
220+
193221 if 0 != bytes .Compare (content , contentExpected ) {
194222 assert .Failf (t , "generated file %s is not the same as %s" , file , expectedFile )
195223 }
@@ -256,7 +284,10 @@ func generateAllFiles(t *testing.T, overwriteExpected bool, conf testSpec, srcDi
256284 assert .Failf (t , "Unexpected PASS on a negative test %s" , sourceFile )
257285 } else {
258286 var unifiedError = strings .Replace (err .Error (), "\\ " , "/" , - 1 ) // "Unify" Windows paths
287+ // Normalize line endings and trim trailing spaces from each line for cross-platform comparison
288+ unifiedError = normalizeErrorString (unifiedError )
259289 expectedError := getExpectedError (t , sourceFile ).Error ()
290+ expectedError = normalizeErrorString (expectedError )
260291 if strings .HasPrefix (unifiedError , "error generating model from schema " ) {
261292 // Compare only the last part of unifiedError as it contains the full path to the schema file
262293 unifiedError = unifiedError [len (unifiedError )- len (expectedError ):]
0 commit comments