Skip to content

Commit 464c602

Browse files
committed
test_suite.py: Make --build-dir work with --build and not just --exec
1 parent f89e20a commit 464c602

File tree

2 files changed

+76
-12
lines changed

2 files changed

+76
-12
lines changed

lnt/tests/test_suite.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,6 @@ def run_test(self, opts):
193193
if opts.exec_mode and opts.build_dir is None and not opts.exec_interleaved_builds:
194194
self._fatal("--exec requires --build-dir (or use --exec-interleaved-builds)")
195195

196-
if opts.build_dir and not opts.exec_mode and not opts.exec_interleaved_builds:
197-
self._fatal("--build-dir can only be used with --exec or --exec-interleaved-builds")
198-
199196
if opts.exec_interleaved_builds:
200197
# --exec-interleaved-builds implies --exec
201198
opts.exec_mode = True
@@ -216,13 +213,15 @@ def run_test(self, opts):
216213
build_dir)
217214

218215
if opts.build_dir:
219-
# Validate build directory
220216
opts.build_dir = os.path.abspath(opts.build_dir)
221-
if not os.path.exists(opts.build_dir):
222-
self._fatal("--build-dir does not exist: %r" % opts.build_dir)
223-
cmakecache = os.path.join(opts.build_dir, 'CMakeCache.txt')
224-
if not os.path.exists(cmakecache):
225-
self._fatal("--build-dir is not a configured build: %r" % opts.build_dir)
217+
# In --exec mode, validate that build_dir already exists and is configured
218+
# In --build mode, we'll create the directory if needed
219+
if opts.exec_mode:
220+
if not os.path.exists(opts.build_dir):
221+
self._fatal("--build-dir does not exist: %r" % opts.build_dir)
222+
cmakecache = os.path.join(opts.build_dir, 'CMakeCache.txt')
223+
if not os.path.exists(cmakecache):
224+
self._fatal("--build-dir is not a configured build: %r" % opts.build_dir)
226225

227226
if opts.cc is not None:
228227
opts.cc = resolve_command_path(opts.cc)
@@ -336,15 +335,15 @@ def run_test(self, opts):
336335
self.start_time = timestamp()
337336

338337
# Work out where to put our build stuff
339-
if opts.exec_mode and opts.build_dir:
340-
# In exec mode with --build-dir, use the specified build directory
338+
if opts.build_dir and (opts.exec_mode or opts.build):
339+
# With --build-dir, use the specified build directory (for both --build and --exec modes)
341340
basedir = opts.build_dir
342341
elif opts.exec_interleaved_builds:
343342
# For exec-interleaved-builds, each build uses its own directory
344343
# We'll return early from _run_interleaved_builds(), so basedir doesn't matter
345344
basedir = opts.sandbox_path
346345
else:
347-
# Normal mode or build mode: use sandbox/build or sandbox/test-<timestamp>
346+
# Normal mode: use sandbox/build or sandbox/test-<timestamp>
348347
if opts.timestamp_build:
349348
ts = self.start_time.replace(' ', '_').replace(':', '-')
350349
build_dir_name = "test-%s" % ts
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Test --build-dir option with --build and --exec modes
2+
3+
# Test 1: --build with --build-dir to create a build in a custom location
4+
# RUN: rm -rf %t.SANDBOX %t.CUSTOM_BUILD
5+
# RUN: mkdir -p %t.CUSTOM_BUILD
6+
# RUN: lnt runtest test-suite \
7+
# RUN: --sandbox %t.SANDBOX \
8+
# RUN: --no-timestamp \
9+
# RUN: --test-suite %S/Inputs/test-suite-cmake \
10+
# RUN: --cc %{shared_inputs}/FakeCompilers/clang-r154331 \
11+
# RUN: --use-cmake %S/Inputs/test-suite-cmake/fake-cmake \
12+
# RUN: --use-make %S/Inputs/test-suite-cmake/fake-make \
13+
# RUN: --use-lit %S/Inputs/test-suite-cmake/fake-lit \
14+
# RUN: --build \
15+
# RUN: --build-dir %t.CUSTOM_BUILD/mybuild \
16+
# RUN: > %t.build.log 2> %t.build.err
17+
# RUN: filecheck --check-prefix CHECK-BUILD-CUSTOM < %t.build.err %s
18+
# CHECK-BUILD-CUSTOM: Building tests (--build mode)...
19+
# CHECK-BUILD-CUSTOM: Build complete. Build directory: {{.*}}CUSTOM_BUILD/mybuild
20+
# CHECK-BUILD-CUSTOM: Use --exec --build-dir {{.*}}CUSTOM_BUILD/mybuild to run tests.
21+
22+
# Verify that build files were created in the custom location
23+
# RUN: test -f %t.CUSTOM_BUILD/mybuild/CMakeCache.txt
24+
25+
# Test 2: --exec with --build-dir using the custom build location
26+
# RUN: lnt runtest test-suite \
27+
# RUN: --sandbox %t.SANDBOX \
28+
# RUN: --no-timestamp \
29+
# RUN: --exec \
30+
# RUN: --build-dir %t.CUSTOM_BUILD/mybuild \
31+
# RUN: --use-cmake %S/Inputs/test-suite-cmake/fake-cmake \
32+
# RUN: --use-lit %S/Inputs/test-suite-cmake/fake-lit \
33+
# RUN: --output %t.exec.report \
34+
# RUN: > %t.exec.log 2> %t.exec.err
35+
# RUN: filecheck --check-prefix CHECK-EXEC-CUSTOM < %t.exec.err %s
36+
# CHECK-EXEC-CUSTOM-NOT: Configuring
37+
# CHECK-EXEC-CUSTOM-NOT: Building
38+
# CHECK-EXEC-CUSTOM: Testing
39+
40+
# Verify that report was created in the custom build directory
41+
# RUN: test -f %t.CUSTOM_BUILD/mybuild/report.json
42+
43+
# Test 3: Error case - --exec with --build-dir pointing to non-existent directory should fail
44+
# RUN: not lnt runtest test-suite \
45+
# RUN: --sandbox %t.SANDBOX \
46+
# RUN: --no-timestamp \
47+
# RUN: --exec \
48+
# RUN: --build-dir %t.NONEXISTENT \
49+
# RUN: --use-lit %S/Inputs/test-suite-cmake/fake-lit \
50+
# RUN: > %t.err1.log 2> %t.err1.err
51+
# RUN: filecheck --check-prefix CHECK-ERR-NONEXISTENT < %t.err1.err %s
52+
# CHECK-ERR-NONEXISTENT: --build-dir does not exist
53+
54+
# Test 4: Error case - --exec with --build-dir pointing to unconfigured directory should fail
55+
# RUN: rm -rf %t.UNCONFIGURED
56+
# RUN: mkdir -p %t.UNCONFIGURED
57+
# RUN: not lnt runtest test-suite \
58+
# RUN: --sandbox %t.SANDBOX \
59+
# RUN: --no-timestamp \
60+
# RUN: --exec \
61+
# RUN: --build-dir %t.UNCONFIGURED \
62+
# RUN: --use-lit %S/Inputs/test-suite-cmake/fake-lit \
63+
# RUN: > %t.err2.log 2> %t.err2.err
64+
# RUN: filecheck --check-prefix CHECK-ERR-UNCONFIGURED < %t.err2.err %s
65+
# CHECK-ERR-UNCONFIGURED: --build-dir is not a configured build

0 commit comments

Comments
 (0)