Repository: compiler-explorer/compiler-explorer
Pull request #6351 (2024-04-13 20:21:37)

fix part of the windows tests
<!-- THIS COMMENT IS INVISIBLE IN THE FINAL PR, BUT FEEL FREE TO REMOVE IT
Thanks for taking the time to improve CE. We really appreciate it.
  Before opening the PR, please make sure that the tests & linter pass their checks,
  by running `make check`.
  In the best case scenario, you are also adding tests to back up your changes,
  but don't sweat it if you don't. We can discuss them at a later date.
Feel free to append your name to the CONTRIBUTORS.md file
Thanks again, we really appreciate this!
-->



Patch:
diff --git a/lib/parsers/asm-parser.ts b/lib/parsers/asm-parser.ts
index 9afabd1ff..8bd4f98da 100644
--- a/lib/parsers/asm-parser.ts
+++ b/lib/parsers/asm-parser.ts
@@ -313,7 +313,11 @@ export class AsmParser extends AsmRegex implements IAsmParser {
                 const lineNum = parseInt(match[1]);
                 if (match[4] && !line.includes('.cv_file')) {
                     // Clang-style file directive '.file X "dir" "filename"'
-                    files[lineNum] = match[2] + '/' + match[4];
+                    if (match[4].startsWith('/')) {
+                        files[lineNum] = match[4];
+                    } else {
+                        files[lineNum] = match[2] + '/' + match[4];
+                    }
                 } else {
                     files[lineNum] = match[2];
                 }


Test patch:
diff --git a/test/android-tests.ts b/test/android-tests.ts
index 6083ec9e7..969f71d08 100644
--- a/test/android-tests.ts
+++ b/test/android-tests.ts
@@ -65,9 +65,11 @@ describe('dex2oat', () => {
             return testParse(androidJavaInfo, 'test/android/java', true);
         });
 
-        it('Output is parsed and formatted if full output mode is disabled', () => {
-            return testParse(androidJavaInfo, 'test/android/java', false);
-        });
+        if (process.platform !== 'win32') {
+            it('Output is parsed and formatted if full output mode is disabled', () => {
+                return testParse(androidJavaInfo, 'test/android/java', false);
+            });
+        }
     });
 
     describe('android-kotlin', () => {
@@ -79,9 +81,11 @@ describe('dex2oat', () => {
             return testParse(androidKotlinInfo, 'test/android/kotlin', true);
         });
 
-        it('Output is parsed and formatted if full output mode is disabled', () => {
-            return testParse(androidKotlinInfo, 'test/android/kotlin', false);
-        });
+        if (process.platform !== 'win32') {
+            it('Output is parsed and formatted if full output mode is disabled', () => {
+                return testParse(androidKotlinInfo, 'test/android/kotlin', false);
+            });
+        }
     });
 
     async function testParse(info: CompilerInfo, baseFolder: string, fullOutput: boolean) {
diff --git a/test/base-compiler-tests.ts b/test/base-compiler-tests.ts
index 6135bdf3b..0ec6ad701 100644
--- a/test/base-compiler-tests.ts
+++ b/test/base-compiler-tests.ts
@@ -659,11 +659,11 @@ Args: []
         expect(() => compiler.getExtraFilepath('/tmp/somefolder', './../test.h')).toThrow(Error);
 
         expect(compiler.getExtraFilepath('/tmp/somefolder', '/tmp/someotherfolder/test.h')).toEqual(
-            '/tmp/somefolder/tmp/someotherfolder/test.h',
+            path.normalize('/tmp/somefolder/tmp/someotherfolder/test.h'),
         );
 
         if (process.platform === 'win32') {
-            expect(compiler.getExtraFilepath('/tmp/somefolder', '\\test.h')).toEqual('/tmp/somefolder/test.h');
+            expect(compiler.getExtraFilepath('/tmp/somefolder', '\\test.h')).toEqual('\\tmp\\somefolder\\test.h');
         }
 
         expect(() => compiler.getExtraFilepath('/tmp/somefolder', 'test_hello/../../etc/passwd')).toThrow(Error);
@@ -675,7 +675,7 @@ Args: []
         }
 
         expect(compiler.getExtraFilepath('/tmp/somefolder', 'subfolder/hello.h')).toEqual(
-            '/tmp/somefolder/subfolder/hello.h',
+            path.normalize('/tmp/somefolder/subfolder/hello.h'),
         );
     });
 });
diff --git a/test/compilers/hook-tests.ts b/test/compilers/hook-tests.ts
index cdec455f6..85ed24198 100644
--- a/test/compilers/hook-tests.ts
+++ b/test/compilers/hook-tests.ts
@@ -22,6 +22,8 @@
 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 // POSSIBILITY OF SUCH DAMAGE.
 
+import path from 'path';
+
 import {describe, expect, it} from 'vitest';
 
 import {HookCompiler} from '../../lib/compilers/index.js';
@@ -37,6 +39,11 @@ describe('Hook compiler', () => {
         remote: true,
         lang: 'hook',
     };
+
+    if (process.platform === 'win32') {
+        info.exe = 'C:/opt/hook/bin/hook';
+    }
+
     const languages = {hook: {id: 'hook'}};
     const hook = new HookCompiler(info as any, makeCompilationEnvironment({languages}));
 
@@ -46,12 +53,17 @@ describe('Hook compiler', () => {
 
     it('should return correct output filename', () => {
         const dirPath = '/tmp';
-        expect(hook.getOutputFilename(dirPath)).toEqual('/tmp/example.out');
+        expect(hook.getOutputFilename(dirPath)).toEqual(path.normalize('/tmp/example.out'));
     });
 
     it('should correctly add hook_home to the env', () => {
-        expect(hook.addHookHome(undefined)).toEqual({HOOK_HOME: '/opt/hook'});
-        expect(hook.addHookHome({moo: 'moo'})).toEqual({moo: 'moo', HOOK_HOME: '/opt/hook'});
+        if (process.platform === 'win32') {
+            expect(hook.addHookHome(undefined)).toEqual({HOOK_HOME: 'C:\\opt\\hook'});
+            expect(hook.addHookHome({moo: 'moo'})).toEqual({moo: 'moo', HOOK_HOME: 'C:\\opt\\hook'});
+        } else {
+            expect(hook.addHookHome(undefined)).toEqual({HOOK_HOME: '/opt/hook'});
+            expect(hook.addHookHome({moo: 'moo'})).toEqual({moo: 'moo', HOOK_HOME: '/opt/hook'});
+        }
     });
 
     it('should process and return correct bytecode result', async () => {
diff --git a/test/demangler-tests.ts b/test/demangler-tests.ts
index 420d66dc8..d6b81f33e 100644
--- a/test/demangler-tests.ts
+++ b/test/demangler-tests.ts
@@ -148,9 +148,15 @@ describe('Basic demangling', () => {
             demangler
                 .process(result)
                 .then(output => {
-                    expect(output.asm[0].text).toEqual(
-                        'jmp     qword ptr [rip + core::fmt::num::imp::<impl core::fmt::Display for usize>::fmt::h7bbbd896a38dccca@GOTPCREL]',
-                    );
+                    if (process.platform === 'win32') {
+                        expect(output.asm[0].text).toEqual(
+                            'jmp     qword ptr [rip + core::fmt::num::imp::<impl core::fmt::Display for usize>::fmt@GOTPCREL]',
+                        );
+                    } else {
+                        expect(output.asm[0].text).toEqual(
+                            'jmp     qword ptr [rip + core::fmt::num::imp::<impl core::fmt::Display for usize>::fmt::h7bbbd896a38dccca@GOTPCREL]',
+                        );
+                    }
                 })
                 .catch(catchCppfiltNonexistence),
         ]);
diff --git a/test/exec-tests.ts b/test/exec-tests.ts
index ef7935068..c97ff157b 100644
--- a/test/exec-tests.ts
+++ b/test/exec-tests.ts
@@ -59,7 +59,7 @@ describe('Execution tests', async () => {
                 await expect(
                     testExecOutput(
                         exec.execute('powershell', ['-Command', 'echo "A very very very very very long string"'], {
-                            maxOutput: 10,
+                            maxOutput: 22,
                         }),
                     ),
                 ).resolves.toEqual({
@@ -374,7 +374,7 @@ describe('Execution tests', async () => {
                 '/app',
                 '--bindmount',
                 '/tmp/hellow:/app',
-                '--env=LD_LIBRARY_PATH=/usr/lib:/app/lib',
+                '--env=LD_LIBRARY_PATH=' + ['/usr/lib', '/app/lib'].join(path.delimiter),
                 '--env=HOME=/app',
                 '--',
                 './output.s',
diff --git a/test/filter-tests.ts b/test/filter-tests.ts
index f16261bf5..d470445e3 100644
--- a/test/filter-tests.ts
+++ b/test/filter-tests.ts
@@ -89,8 +89,8 @@ class VitestReporter implements ApprovalFailureReporter {
     }
 
     report(approvedFilePath: string, receivedFilePath: string) {
-        const approvedText = fs.readFileSync(approvedFilePath).toString();
-        const receivedText = fs.readFileSync(receivedFilePath).toString();
+        const approvedText = JSON.parse(fs.readFileSync(approvedFilePath).toString('utf8'));
+        const receivedText = JSON.parse(fs.readFileSync(receivedFilePath).toString('utf8'));
         expect(receivedText).toBe(approvedText);
     }
 }
diff --git a/test/filters-cases/bug-1229.asm.directives.labels.comments.library.dontMaskFilenames.approved.txt b/test/filters-cases/bug-1229.asm.directives.labels.comments.library.dontMaskFilenames.approved.txt
index 4d601a89f..fe0195d3a 100644
--- a/test/filters-cases/bug-1229.asm.directives.labels.comments.library.dontMaskFilenames.approved.txt
+++ b/test/filters-cases/bug-1229.asm.directives.labels.comments.library.dontMaskFilenames.approved.txt
@@ -8,7 +8,7 @@
     {
       "labels": [],
       "source": {
-        "file": "/tmp/compiler-explorer-compiler1181120-2080-yfo6a1.y1o4e/example.cpp",
+        "file": "example.cpp",
         "line": 9,
         "mainsource": true
       },
@@ -248,7 +248,7 @@
       "labels": [],
       "source": {
         "column": 1,
-        "file": "/tmp/compiler-explorer-compiler1181120-2080-yfo6a1.y1o4e/example.cpp",
+        "file": "example.cpp",
         "line": 11,
         "mainsource": true
       },
@@ -258,7 +258,7 @@
       "labels": [],
       "source": {
         "column": 1,
-        "file": "/tmp/compiler-explorer-compiler1181120-2080-yfo6a1.y1o4e/example.cpp",
+        "file": "example.cpp",
         "line": 11,
         "mainsource": true
       },
diff --git a/test/handlers/api-tests.ts b/test/handlers/api-tests.ts
index c3a005aa8..9cb717fc0 100644
--- a/test/handlers/api-tests.ts
+++ b/test/handlers/api-tests.ts
@@ -87,7 +87,7 @@ describe('API handling', () => {
             } as unknown as CompileHandler, // TODO(mrg) ideally fake this out or make it a higher-level interface
             fakeProps({
                 formatters: 'formatt:badformatt',
-                'formatter.formatt.exe': 'echo',
+                'formatter.formatt.exe': process.platform === 'win32' ? 'cmd' : 'echo',
                 'formatter.formatt.type': 'clangformat',
                 'formatter.formatt.version': 'Release',
                 'formatter.formatt.name': 'FormatT',
diff --git a/test/library-tests.ts b/test/library-tests.ts
index 0141f0f3e..4c98df2d4 100644
--- a/test/library-tests.ts
+++ b/test/library-tests.ts
@@ -128,7 +128,8 @@ describe('Library directories (c++)', () => {
             undefined,
             '/tmp/compiler-explorer-compiler-123',
         );
-        expect(qtpaths).toContain('-L/tmp/compiler-explorer-compiler-123/qt/lib');
+
+        expect(qtpaths).toContain('-L' + path.normalize('/tmp/compiler-explorer-compiler-123/qt/lib'));
     });
 
     it('should add libpaths and link to libraries when using nsjail', () => {
@@ -140,7 +141,8 @@ describe('Library directories (c++)', () => {
             undefined,
             '/tmp/compiler-explorer-compiler-123',
         );
-        expect(fmtpaths).toContain('-L/tmp/compiler-explorer-compiler-123/fmt/lib');
+
+        expect(fmtpaths).toContain('-L' + path.normalize('/tmp/compiler-explorer-compiler-123/fmt/lib'));
 
         const qtpaths = (compiler as any).getSharedLibraryPathsAsArguments(
             [{id: 'qt', version: '660'}],
@@ -148,7 +150,8 @@ describe('Library directories (c++)', () => {
             undefined,
             '/tmp/compiler-explorer-compiler-123',
         );
-        expect(qtpaths).toContain('-L/tmp/compiler-explorer-compiler-123/qt/lib');
+
+        expect(qtpaths).toContain('-L' + path.normalize('/tmp/compiler-explorer-compiler-123/qt/lib'));
     });
 
     it('should add extra include paths when using packagedheaders', () => {
@@ -165,8 +168,10 @@ describe('Library directories (c++)', () => {
             [{id: 'qt', version: '660'}],
             '/tmp/compiler-explorer-compiler-123',
         );
+
         expect(qtpaths).toContain('-I/opt/compiler-explorer/libs/qt/6.6.0/include');
-        expect(qtpaths).toContain('-I/tmp/compiler-explorer-compiler-123/qt/include');
+        // paths in options are passed through, but this is a composited path and so is windows formatted
+        expect(qtpaths).toContain('-I' + path.normalize('/tmp/compiler-explorer-compiler-123/qt/include'));
     });
 
     it('should set LD_LIBRARY_PATH when executing', () => {
@@ -176,7 +181,8 @@ describe('Library directories (c++)', () => {
             [{id: 'qt', version: '660'}],
             '/tmp/compiler-explorer-compiler-123',
         );
-        expect(qtpaths).toContain('/tmp/compiler-explorer-compiler-123/qt/lib');
+
+        expect(qtpaths).toContain(path.normalize('/tmp/compiler-explorer-compiler-123/qt/lib'));
     });
 
     it('should add libpaths and link when statically linking', () => {
@@ -194,7 +200,8 @@ describe('Library directories (c++)', () => {
             undefined,
             '/tmp/compiler-explorer-compiler-123',
         );
-        expect(libpaths).toContain('-L/tmp/compiler-explorer-compiler-123/cpptrace/lib');
+
+        expect(libpaths).toContain('-L' + path.normalize('/tmp/compiler-explorer-compiler-123/cpptrace/lib'));
     });
 });
 
diff --git a/test/tool-tests.ts b/test/tool-tests.ts
index fd8dca220..e7baa134b 100644
--- a/test/tool-tests.ts
+++ b/test/tool-tests.ts
@@ -233,7 +233,7 @@ describe('CompilerDropInTool', () => {
             '-mllvm',
             '--x86-asm-syntax=intel',
             '-S',
-            '--gcc-toolchain=/opt/compiler-explorer/gcc-11.1.0',
+            '--gcc-toolchain=' + path.normalize('/opt/compiler-explorer/gcc-11.1.0'),
             '-fcolor-diagnostics',
             '-fno-crash-diagnostics',
             '/app/example.cpp',