west: build: handler errors in west build with --test-item
Handle errors and wrong test meta-data when using --test-item.
Fixes #52614
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
diff --git a/scripts/west_commands/build.py b/scripts/west_commands/build.py
index 0c62213..0063173 100644
--- a/scripts/west_commands/build.py
+++ b/scripts/west_commands/build.py
@@ -156,7 +156,8 @@
self._parse_remainder(remainder)
# Parse testcase.yaml or sample.yaml files for additional options.
if self.args.test_item:
- self._parse_test_item()
+ if not self._parse_test_item():
+ log.die("No test metadata found")
if source_dir:
if self.args.source_dir:
log.die("source directory specified twice:({} and {})".format(
@@ -246,10 +247,12 @@
return
def _parse_test_item(self):
+ found_test_metadata = False
for yp in ['sample.yaml', 'testcase.yaml']:
yf = os.path.join(self.args.source_dir, yp)
if not os.path.exists(yf):
continue
+ found_test_metadata = True
with open(yf, 'r') as stream:
try:
y = yaml.safe_load(stream)
@@ -257,10 +260,10 @@
log.die(exc)
tests = y.get('tests')
if not tests:
- continue
+ log.die(f"No tests found in {yf}")
item = tests.get(self.args.test_item)
if not item:
- continue
+ log.die(f"Test item {self.args.test_item} not found in {yf}")
for data in ['extra_args', 'extra_configs']:
extra = item.get(data)
@@ -275,6 +278,7 @@
self.args.cmake_opts.extend(args)
else:
self.args.cmake_opts = args
+ return found_test_metadata
def _sanity_precheck(self):
app = self.args.source_dir