test(backend): add GCC include path syntax test for Windows platform

- Add testGccOnWindowsUsesGccIncludeSyntaxForAllSourceTypes method to verify include path formatting
- Test include paths with GCC compiler on Windows for C, C++, and assembler files
- Verify that GCC uses -I flag syntax instead of /I for all source types on Windows
- Confirm proper escaping of include paths with spaces using escapeshellarg
- Add formatIncludePaths method to handle include flag formatting consistently across platforms
master
韩天峰 3 weeks ago
parent 745556fee8
commit db305c11f5
  1. 21
      phpunit/src/Backend/BackendTest.php
  2. 11
      src/Backend/GccLikeBackend.php

@ -213,6 +213,27 @@ class BackendTest extends TestCase
$this->assertStringContainsString('-fno-rtti', $cmd);
}
public function testGccOnWindowsUsesGccIncludeSyntaxForAllSourceTypes(): void
{
$compiler = new Gcc(new Windows());
$includePaths = ['C:\\phpx\\include', 'C:\\Program Files\\PHP\\include'];
$options = [
'include_paths' => $includePaths,
];
$commands = [
$compiler->buildCompileCommand('test.cpp', 'test.obj', $options),
$compiler->buildCCompileCommand('test.c', 'test.obj', $options),
$compiler->buildNativeCompileCommand('test.S', 'test.obj', $options, 'assembler'),
];
foreach ($commands as $cmd) {
foreach ($includePaths as $path) {
$this->assertStringContainsString('-I' . escapeshellarg($path), $cmd);
}
$this->assertStringNotContainsString('/I ', $cmd);
}
}
public function testGccBuildCCompileCommandKeepsSharedCompilerOptions(): void
{
$platform = new Linux();

@ -51,6 +51,17 @@ abstract class GccLikeBackend extends CompilerBackend
return '-o';
}
/** Include flag syntax is defined by the compiler driver, not the host platform. */
protected function formatIncludePaths(array $includePaths): string
{
$flags = [];
foreach ($includePaths as $path) {
$flags[] = '-I' . escapeshellarg($path);
}
return implode(' ', $flags);
}
/** Format the sanitizer flag. */
protected function formatSanitizerFlag(string $sanitizer): string
{

Loading…
Cancel
Save