Skip to content

Commit ffca377

Browse files
feat(ci): build_examples 加 ctest 验证 example 测试绿
build_project 在 build 后检测 CTestTestfile.cmake: 有测试的工程(目前 vol5-labs)跑 ctest, 没配 CTest 的纯示例跳过、不误伤。CI 现在验证 example 参考实现测试全绿。
1 parent 2207dd6 commit ffca377

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

scripts/build_examples.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,25 @@ def build_project(project_dir: Path) -> BuildResult:
163163
success = False
164164
all_output.append('Build timed out (300s)')
165165

166+
# 跑测试(仅当工程配了 CTest: build_dir 里有 CTestTestfile.cmake)。
167+
# 没配 CTest 的工程(大多数纯示例)直接跳过, 不算失败。
168+
if success and (build_dir / 'CTestTestfile.cmake').exists():
169+
ctest_cmd = ['ctest', '--test-dir', str(build_dir),
170+
'--output-on-failure', '--timeout', '60']
171+
try:
172+
ct = subprocess.run(ctest_cmd, cwd=str(project_dir),
173+
capture_output=True, text=True, timeout=180)
174+
all_output.append('--- ctest ---')
175+
all_output.append(ct.stdout)
176+
all_output.append(ct.stderr)
177+
if ct.returncode != 0:
178+
success = False
179+
except subprocess.TimeoutExpired:
180+
all_output.append('ctest timed out (180s)')
181+
success = False
182+
except FileNotFoundError:
183+
pass # 环境没 ctest, 跳过
184+
166185
duration = time.time() - start
167186

168187
# Cleanup build dir

0 commit comments

Comments
 (0)