Skip to content

Commit d9e52cc

Browse files
authored
[libc++] Optionally support filecheck and split-file (llvm#165769)
This patch adds optional support for FileCheck and split-file in libc++'s test suite. Whether FileCheck / split-file is available can be queried using Lit features. This should make it possible to test several things that were previously impossible to test, especially for specific code generation. Supersedes llvm#65917 and llvm#188283
1 parent 1be9eed commit d9e52cc

File tree

7 files changed

+107
-5
lines changed

7 files changed

+107
-5
lines changed

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ jobs:
5858
with:
5959
persist-credentials: false
6060
- name: ${{ matrix.config }}.${{ matrix.cxx }}
61-
run: libcxx/utils/ci/run-buildbot ${{ matrix.config }}
61+
run: |
62+
python3 -m venv --system-site-packages .venv
63+
source .venv/bin/activate
64+
pip install -r libcxx/test/requirements.txt
65+
libcxx/utils/ci/run-buildbot ${{ matrix.config }}
6266
env:
6367
CC: ${{ matrix.cc }}
6468
CXX: ${{ matrix.cxx }}
@@ -105,7 +109,11 @@ jobs:
105109
with:
106110
persist-credentials: false
107111
- name: ${{ matrix.config }}
108-
run: libcxx/utils/ci/run-buildbot ${{ matrix.config }}
112+
run: |
113+
python3 -m venv --system-site-packages .venv
114+
source .venv/bin/activate
115+
pip install -r libcxx/test/requirements.txt
116+
libcxx/utils/ci/run-buildbot ${{ matrix.config }}
109117
env:
110118
CC: ${{ matrix.cc }}
111119
CXX: ${{ matrix.cxx }}
@@ -162,7 +170,11 @@ jobs:
162170
with:
163171
persist-credentials: false
164172
- name: ${{ matrix.config }}
165-
run: libcxx/utils/ci/run-buildbot ${{ matrix.config }}
173+
run: |
174+
python3 -m venv --system-site-packages .venv
175+
source .venv/bin/activate
176+
pip install -r libcxx/test/requirements.txt
177+
libcxx/utils/ci/run-buildbot ${{ matrix.config }}
166178
env:
167179
CC: clang-22
168180
CXX: clang++-22
@@ -220,7 +232,7 @@ jobs:
220232
run: |
221233
python3 -m venv .venv
222234
source .venv/bin/activate
223-
python -m pip install psutil
235+
pip install -r libcxx/test/requirements.txt
224236
xcrun bash libcxx/utils/ci/run-buildbot ${{ matrix.config }}
225237
env:
226238
CC: clang
@@ -260,7 +272,7 @@ jobs:
260272
persist-credentials: false
261273
- name: Install dependencies
262274
run: |
263-
pip install psutil
275+
pip install -r libcxx/test/requirements.txt
264276
- name: Install a current LLVM
265277
if: ${{ matrix.mingw != true }}
266278
run: |

libcxx/docs/TestingLibcxx.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ Please see the `Lit Command Guide`_ for more information about LIT.
2323

2424
.. _LIT Command Guide: https://llvm.org/docs/CommandGuide/lit.html
2525

26+
Dependencies
27+
------------
28+
29+
The libc++ test suite has a few optional dependencies. These can be installed
30+
with ``pip install -r libcxx/test/requirements.txt``. Installing these dependencies
31+
will ensure that the maximum number of tests can be run.
32+
2633
Usage
2734
-----
2835

libcxx/test/requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# This file defines Python requirements to run the libc++ test suite.
3+
#
4+
llvm-testing-tools==23.0.0
5+
psutil==5.9.8
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: has-filecheck
10+
11+
// Make sure that FileCheck fails when it should fail. This ensure that FileCheck
12+
// actually checks the content of the file.
13+
14+
// RUN: echo "hello world" | not FileCheck %s
15+
// CHECK: foobar
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: has-filecheck
10+
11+
// Make sure that we can use FileCheck to write tests when the `has-filecheck`
12+
// Lit feature is defined.
13+
14+
// RUN: echo "hello world" | FileCheck %s
15+
// CHECK: hello world
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: has-splitfile
10+
11+
// Make sure that we can use split-file to write tests when the `has-splitfile`
12+
// Lit feature is defined.
13+
14+
// RUN: split-file %s %{temp}
15+
16+
// RUN: grep 'int main' %{temp}/main.cpp
17+
// RUN: grep 'return 0' %{temp}/main.cpp
18+
// RUN: not grep -c 'Pre-delimiter' %{temp}/main.cpp
19+
// RUN: not grep -c 'foo' %{temp}/main.cpp
20+
// RUN: not grep -c '//---' %{temp}/main.cpp
21+
22+
// RUN: grep foo %{temp}/input.txt
23+
// RUN: grep bar %{temp}/input.txt
24+
// RUN: not grep -c 'Pre-delimiter' %{temp}/input.txt
25+
// RUN: not grep -c 'int main' %{temp}/input.txt
26+
// RUN: not grep -c '//---' %{temp}/input.txt
27+
28+
// Pre-delimiter comment.
29+
30+
//--- main.cpp
31+
32+
int main() {
33+
return 0;
34+
}
35+
36+
//--- input.txt
37+
38+
foo
39+
bar

libcxx/utils/libcxx/test/features/misc.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,13 @@ def _mingwSupportsModules(cfg):
296296
""",
297297
),
298298
),
299+
# Whether `FileCheck` and `split-file` executables are available.
300+
Feature(
301+
name="has-filecheck",
302+
when=lambda cfg: runScriptExitCode(cfg, ["FileCheck --version"]) == 0,
303+
),
304+
Feature(
305+
name="has-splitfile",
306+
when=lambda cfg: runScriptExitCode(cfg, ["split-file --version"]) == 0,
307+
),
299308
]

0 commit comments

Comments
 (0)