Skip to content

Commit 6e11c84

Browse files
committed
Check if current directory has tests before error
1 parent 70d42c7 commit 6e11c84

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

btest

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,7 @@ class LinuxTimer(TimerBase):
24452445

24462446

24472447
# Walk the given directory and return all test files.
2448-
def findTests(paths, expand_globs=False):
2448+
def findTests(paths, *, cwd=None, expand_globs=False):
24492449
tests = []
24502450

24512451
ignore_files = getOption("IgnoreFiles", "").split()
@@ -2454,14 +2454,20 @@ def findTests(paths, expand_globs=False):
24542454
expanded = set()
24552455

24562456
for p in paths:
2457-
p = os.path.join(TestBase, p)
2457+
anchored = os.path.join(TestBase, p)
24582458

24592459
if expand_globs:
2460-
for d in glob.glob(p):
2460+
for d in glob.glob(anchored):
24612461
if os.path.isdir(d):
24622462
expanded.add(d)
24632463
else:
2464-
expanded.add(p)
2464+
# Allow relative directories if this one does not exist
2465+
if cwd and not os.path.exists(anchored):
2466+
from_cwd = cwd / p
2467+
if from_cwd.exists():
2468+
anchored = str(from_cwd)
2469+
2470+
expanded.add(anchored)
24652471

24662472
for path in expanded:
24672473
rpath = os.path.relpath(path, TestBase)
@@ -3081,6 +3087,7 @@ if __name__ == "__main__":
30813087
transform=lambda x: normalize_path(x),
30823088
)
30833089

3090+
orig_cwd = pathlib.Path.cwd()
30843091
os.chdir(TestBase)
30853092

30863093
if Options.sphinx:
@@ -3216,13 +3223,13 @@ if __name__ == "__main__":
32163223

32173224
testdirs = getOption("TestDirs", "").split()
32183225
if testdirs:
3219-
Config.configured_tests = findTests(testdirs, True)
3226+
Config.configured_tests = findTests(testdirs, expand_globs=True)
32203227

32213228
if args:
32223229
if Options.tests_file:
32233230
error("cannot specify tests both on command line and with --tests-file")
32243231

3225-
tests = findTests(args)
3232+
tests = findTests(args, cwd=orig_cwd)
32263233

32273234
else:
32283235
if Options.rerun:

testing/tests/resolve-from-cwd.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# %TEST-DOC: Ensure btest can find tests from a path relative to the current directory
2+
#
3+
# %TEST-EXEC: mkdir -p my/relative/dir
4+
# %TEST-EXEC: cat %INPUT >> my/relative/dir/a-relative-test.test
5+
# %TEST-EXEC: cd my/relative/dir && btest a-relative-test.test
6+
# %TEST-EXEC: cd my/relative && btest dir/a-relative-test.test
7+
8+
@TEST-EXEC: exit 0

0 commit comments

Comments
 (0)