@@ -150,33 +150,66 @@ def _run_init_script(self):
150150 except subprocess .CalledProcessError :
151151 pass # Non-fatal if init fails
152152
153+ def _resolve_test_arg (self , t : str ):
154+ """
155+ Resolve one command-line test argument to (name, path).
156+
157+ A test may be named relative to the tests topdir ('lcov/xs_test') or
158+ relative to the current directory -- the latter is what 'make check' in
159+ a leaf directory produces, because common.mak passes the directory's own
160+ $(TESTS) ('xs1.sh') to a driver that used to look only under
161+ topdir. That mismatch made every leaf-directory 'make check' report
162+ "No tests found". Try topdir first (the historical behaviour, and the
163+ form a user typing a path from the tests root uses), then the
164+ invocation directory.
165+
166+ The returned NAME is always relative to topdir, so the per-test log
167+ file and coverage database are identified the same way no matter which
168+ directory the run was launched from.
169+ """
170+ for base in (self .topdir , Path .cwd ()):
171+ path = (base / t )
172+ if not path .exists ():
173+ continue
174+ path = path .resolve ()
175+ try :
176+ name = str (path .relative_to (self .topdir .resolve ()))
177+ except ValueError :
178+ # Outside the tests tree: fall back to the name as given.
179+ name = t
180+ return name , path
181+ return None , None
182+
153183 def discover_tests (self , makefile_path : Path = None ):
154184 """
155185 Discover tests from Makefile TESTS variable or command line.
156186 Returns list of (test_name, test_path) tuples.
157187 """
158188 tests = []
159-
189+
160190 if self .args .tests :
161191 # Explicit tests from command line
162192 for t in self .args .tests :
163- test_path = self .topdir / t
193+ name , test_path = self ._resolve_test_arg (t )
194+ if test_path is None :
195+ print (f"Warning: test '{ t } ' not found" , file = sys .stderr )
196+ continue
164197 if test_path .is_dir ():
165198 # Check if it has a Makefile with TESTS
166199 sub_makefile = test_path / 'Makefile'
167200 if sub_makefile .exists ():
168201 sub_tests = self ._parse_tests_variable (sub_makefile )
169202 if sub_tests :
170203 # Recurse into this directory
171- tests .extend (self ._discover_from_makefile (sub_makefile , t ))
204+ tests .extend (self ._discover_from_makefile (sub_makefile , name ))
172205 else :
173206 # Leaf directory - find scripts
174- tests .extend (self ._discover_in_dir (test_path , t ))
207+ tests .extend (self ._discover_in_dir (test_path , name ))
175208 else :
176209 # No Makefile, find scripts
177- tests .extend (self ._discover_in_dir (test_path , t ))
178- elif test_path . exists () :
179- tests .append ((t , test_path ))
210+ tests .extend (self ._discover_in_dir (test_path , name ))
211+ else :
212+ tests .append ((name , test_path ))
180213 else :
181214 # Discover from Makefile
182215 makefile = makefile_path or (self .topdir / 'Makefile' )
0 commit comments