Merge pull request #19410 from jketema/header-variant

C++: Turn header variant tests that use PCH files into integration tests
This commit is contained in:
Jeroen Ketema
2025-04-30 20:10:30 +02:00
committed by GitHub
36 changed files with 64 additions and 53 deletions

View File

@@ -0,0 +1,2 @@
#include "a.h"
#define FOUR 4

View File

@@ -0,0 +1,3 @@
int main() {
return ONE + FOUR;
}

View File

@@ -0,0 +1 @@
#import "d.h"

View File

@@ -0,0 +1,3 @@
int main() {
return SEVENTEEN;
}

View File

@@ -0,0 +1,5 @@
#if 1
#pragma hdrstop
extern int x;
#define SEEN_F
#endif

View File

@@ -0,0 +1,5 @@
#ifdef SEEN_F
static int g() {
return 20;
}
#endif

View File

@@ -0,0 +1,4 @@
#include "h1.h"
#pragma hdrstop
#include "h2.h"
#define SEEN_H

View File

@@ -13,4 +13,3 @@ static int h2() {
return 32;
}
#endif
// semmle-extractor-options: --clang -include-pch ${testdir}/clang-pch.testproj/h.pch

View File

@@ -0,0 +1,17 @@
import os
def test(codeql, cpp):
os.mkdir("pch")
extractor = cpp.get_tool("extractor")
codeql.database.create(command=[
f'"{extractor}" --mimic-clang -emit-pch -o pch/a.pch a.c',
f'"{extractor}" --mimic-clang -include-pch pch/a.pch -Iextra_dummy_path b.c',
f'"{extractor}" --mimic-clang -include pch/a -Iextra_dummy_path c.c',
f'"{extractor}" --mimic-clang -emit-pch -o pch/d.pch d.c',
f'"{extractor}" --mimic-clang -include-pch pch/d.pch e.c',
f'"{extractor}" --mimic-clang -emit-pch -o pch/f.pch f.c',
f'"{extractor}" --mimic-clang -include-pch pch/f.pch g.c',
f'"{extractor}" --mimic-clang -emit-pch -o pch/h.pch h.c',
f'"{extractor}" --mimic-clang -include-pch pch/h.pch i.c',
])

View File

@@ -0,0 +1 @@
#include "a.h"

View File

@@ -0,0 +1,6 @@
#pragma hdrstop
#include "b.h"
int b() {
return A;
}

View File

@@ -0,0 +1,6 @@
#include "d.h"
#include "c.h"
int c() {
return A;
}

View File

@@ -0,0 +1,11 @@
import os
def test(codeql, cpp):
os.mkdir("pch")
extractor = cpp.get_tool("extractor")
codeql.database.create(command=[
f'"{extractor}" --mimic-cl /Yca.h /Fppch/a.pch a.c',
f'"{extractor}" --mimic-cl /Yub.h /Fppch/a.pch b.c',
f'"{extractor}" --mimic-cl /Yuc.h /Fppch/a.pch c.c',
])

View File

@@ -1,3 +0,0 @@
// This file exists to ensure that the output subdirectory exists prior to
// a.c being indexed, as said directory needs to exist for the PCH file to
// be created, and will be created by running the extractor.

View File

@@ -1,3 +0,0 @@
#include "a.h"
#define FOUR 4
// semmle-extractor-options: --clang -emit-pch -o ${testdir}/clang-pch.testproj/a.pch

View File

@@ -1,4 +0,0 @@
int main() {
return ONE + FOUR;
}
// semmle-extractor-options: --clang -include ${testdir}/clang-pch.testproj/a -Iextra_dummy_path

View File

@@ -1,2 +0,0 @@
#import "d.h"
// semmle-extractor-options: --clang -emit-pch -o ${testdir}/clang-pch.testproj/d.pch

View File

@@ -1,4 +0,0 @@
int main() {
return SEVENTEEN;
}
// semmle-extractor-options: --clang -include-pch ${testdir}/clang-pch.testproj/d.pch

View File

@@ -1,6 +0,0 @@
#if 1
#pragma hdrstop
extern int x;
#define SEEN_F
#endif
// semmle-extractor-options: --clang -emit-pch -o ${testdir}/clang-pch.testproj/f.pch

View File

@@ -1,6 +0,0 @@
#ifdef SEEN_F
static int g() {
return 20;
}
#endif
// semmle-extractor-options: --clang -include-pch ${testdir}/clang-pch.testproj/f.pch

View File

@@ -1,5 +0,0 @@
#include "h1.h"
#pragma hdrstop
#include "h2.h"
#define SEEN_H
// semmle-extractor-options: --clang -emit-pch -o ${testdir}/clang-pch.testproj/h.pch

View File

@@ -1,3 +0,0 @@
// This file exists to ensure that the output subdirectory exists prior to
// a.c being indexed, as said directory needs to exist for the PCH file to
// be created, and will be created by running the extractor.

View File

@@ -1,2 +0,0 @@
#include "a.h"
// semmle-extractor-options: --microsoft /Yca.h /Fp${testdir}/microsoft-pch.testproj/a.pch

View File

@@ -1,7 +0,0 @@
#pragma hdrstop
#include "b.h"
int b() {
return A;
}
// semmle-extractor-options: --microsoft /Yub.h /Fp${testdir}/microsoft-pch.testproj/a.pch

View File

@@ -1,7 +0,0 @@
#include "d.h"
#include "c.h"
int c() {
return A;
}
// semmle-extractor-options: --microsoft /Yuc.h /Fp${testdir}/microsoft-pch.testproj/a.pch