C++: Turn header variant tests that use PCH files into integration tests

These tests currently test a code path in the extractor that only exists for
these tests. By turning them into integration tests, we actually use the
code path that normal database creation uses.
This commit is contained in:
Jeroen Ketema
2025-04-29 13:16:40 +02:00
parent e5d296180b
commit 7f9020282d
36 changed files with 62 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,16 @@
import os
def test(codeql, cpp):
os.mkdir("pch")
codeql.database.create(command=[
f'"{cpp.get_tool("extractor")}" --mimic-clang -emit-pch -o pch/a.pch a.c',
f'"{cpp.get_tool("extractor")}" --mimic-clang -include-pch pch/a.pch -Iextra_dummy_path b.c',
f'"{cpp.get_tool("extractor")}" --mimic-clang -include pch/a -Iextra_dummy_path c.c',
f'"{cpp.get_tool("extractor")}" --mimic-clang -emit-pch -o pch/d.pch d.c',
f'"{cpp.get_tool("extractor")}" --mimic-clang -include-pch pch/d.pch e.c',
f'"{cpp.get_tool("extractor")}" --mimic-clang -emit-pch -o pch/f.pch f.c',
f'"{cpp.get_tool("extractor")}" --mimic-clang -include-pch pch/f.pch g.c',
f'"{cpp.get_tool("extractor")}" --mimic-clang -emit-pch -o pch/h.pch h.c',
f'"{cpp.get_tool("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,10 @@
import os
def test(codeql, cpp):
os.mkdir("pch")
codeql.database.create(command=[
f'"{cpp.get_tool("extractor")}" --mimic-cl /Yca.h /Fppch/a.pch a.c',
f'"{cpp.get_tool("extractor")}" --mimic-cl /Yub.h /Fppch/a.pch b.c',
f'"{cpp.get_tool("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