west: build: handler errors in west build with --test-item
Handle errors and wrong test meta-data when using --test-item.
Fixes
@@ -156,7 +156,8 @@ class Build(Forceable):
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 @@ class Build(Forceable):
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 @@ class Build(Forceable):
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 @@ class Build(Forceable):
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
