Skip to content

Commit 8687a93

Browse files
committed
tests: skip closure boehm steps when libgc is unavailable (fix ubuntu-musl CI)
The closure_lifetime_api and closure_context_skip_unused tests shell out to '-gc boehm'/'-gc boehm_leak' subprocesses and assert success. On the docker-ubuntu-musl image there is no musl-compatible Boehm GC library, so those builds fail with 'ld: cannot find -lgc'. The existing missing-lib guard only covered boehm_leak mode and matched the substring 'libgc', which the musl linker error does not contain. Broaden the detector to recognize the real error formats (-lgc, -lgc-threaded, macOS "library 'gc' not found", missing libgc.so) and apply the skip-when-missing guard to all non-none GC modes. Boehm coverage is preserved wherever the library is available (alpine, glibc, macOS); only genuine missing-lib failures are skipped.
1 parent a3c8c55 commit 8687a93

2 files changed

Lines changed: 31 additions & 17 deletions

File tree

vlib/v/tests/fns/closure_context_skip_unused_test.v

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import os
22

33
const vexe = @VEXE
44

5-
fn missing_boehm_leak_lib(output string) bool {
6-
return output.contains('libgc') && (output.contains('was not found')
7-
|| output.contains('cannot find'))
5+
fn missing_boehm_lib(output string) bool {
6+
mentions_gc := output.contains('libgc') || output.contains('-lgc')
7+
|| output.contains("library 'gc'") || output.contains('bdw-gc')
8+
return mentions_gc && (output.contains('was not found')
9+
|| output.contains('cannot find') || output.contains('not found')
10+
|| output.contains('No such file'))
811
}
912

1013
fn closure_skip_unused_source() string {
@@ -61,9 +64,8 @@ fn run_closure_skip_unused_case(tmp_dir string, mode string) {
6164
os.write_file(source_path, closure_skip_unused_source()) or { panic(err) }
6265
compile_cmd := '${os.quoted_path(vexe)} -skip-unused -gc ${mode} -o ${os.quoted_path(binary_path)} ${os.quoted_path(source_path)}'
6366
compile_res := os.execute(compile_cmd)
64-
if mode == 'boehm_leak' && compile_res.exit_code != 0
65-
&& missing_boehm_leak_lib(compile_res.output) {
66-
eprintln('skipping boehm_leak closure skip-unused test: missing libgc')
67+
if mode != 'none' && compile_res.exit_code != 0 && missing_boehm_lib(compile_res.output) {
68+
eprintln('skipping ${mode} closure skip-unused test: missing libgc')
6769
return
6870
}
6971
assert compile_res.exit_code == 0, compile_res.output

vlib/v/tests/fns/closure_lifetime_api_test.v

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,24 @@ fn skip_test(reason string) {
1414
exit(0)
1515
}
1616

17-
fn missing_boehm_leak_lib(output string) bool {
18-
return output.contains('libgc') && (output.contains('was not found')
19-
|| output.contains('cannot find'))
17+
fn missing_boehm_lib(output string) bool {
18+
mentions_gc := output.contains('libgc') || output.contains('-lgc')
19+
|| output.contains("library 'gc'") || output.contains('bdw-gc')
20+
return mentions_gc && (output.contains('was not found')
21+
|| output.contains('cannot find') || output.contains('not found')
22+
|| output.contains('No such file'))
23+
}
24+
25+
// assert_run_succeeds_or_missing_boehm runs the program with the given gc mode and
26+
// asserts success, but skips gracefully when a `boehm`/`boehm_leak` build fails only
27+
// because the Boehm GC library is unavailable (e.g. musl images without musl libgc).
28+
fn assert_run_succeeds_or_missing_boehm(tmp_dir string, name string, source string, mode string) {
29+
res := run_program_with_gc(tmp_dir, name, source, mode)
30+
if mode != 'none' && res.exit_code != 0 && missing_boehm_lib(res.output) {
31+
eprintln('skipping ${mode} run for ${name}: missing libgc')
32+
return
33+
}
34+
assert res.exit_code == 0, res.output
2035
}
2136

2237
fn count_occurrences(haystack string, needle string) int {
@@ -65,7 +80,7 @@ fn c_output_for_program(tmp_dir string, name string, source string) os.Result {
6580

6681
fn assert_boehm_leak_compile_or_missing_lib(tmp_dir string, name string, source string) {
6782
res := compile_program_with_gc(tmp_dir, name, source, 'boehm_leak')
68-
if res.exit_code != 0 && missing_boehm_leak_lib(res.output) {
83+
if res.exit_code != 0 && missing_boehm_lib(res.output) {
6984
eprintln('skipping boehm_leak compile for ${name}: missing libgc')
7085
return
7186
}
@@ -77,7 +92,7 @@ fn assert_boehm_leak_runtime_or_compile_only(tmp_dir string, name string, source
7792
if res.exit_code == 0 {
7893
return
7994
}
80-
if missing_boehm_leak_lib(res.output) {
95+
if missing_boehm_lib(res.output) {
8196
eprintln('skipping boehm_leak runtime for ${name}: missing libgc')
8297
return
8398
}
@@ -589,8 +604,7 @@ fn test_lifetime_public_api_without_captured_closure() {
589604
assert !c_res.output.contains('builtin__closure__closure_create')
590605
assert !c_res.output.contains('_V_closure_main__')
591606
for mode in ['boehm', 'none'] {
592-
res := run_program_with_gc(tmp_dir, 'no_captured_lifetime', source, mode)
593-
assert res.exit_code == 0, res.output
607+
assert_run_succeeds_or_missing_boehm(tmp_dir, 'no_captured_lifetime', source, mode)
594608
}
595609
assert_boehm_leak_compile_or_missing_lib(tmp_dir, 'no_captured_lifetime', source)
596610
}
@@ -606,8 +620,7 @@ fn test_closure_lifetime_runtime_api_contract() {
606620
}
607621
source := closure_lifetime_runtime_source()
608622
for mode in ['boehm', 'none'] {
609-
res := run_program_with_gc(tmp_dir, 'closure_lifetime_runtime', source, mode)
610-
assert res.exit_code == 0, res.output
623+
assert_run_succeeds_or_missing_boehm(tmp_dir, 'closure_lifetime_runtime', source, mode)
611624
}
612625
assert_boehm_leak_compile_or_missing_lib(tmp_dir, 'closure_lifetime_runtime', source)
613626
}
@@ -713,8 +726,7 @@ fn test_closure_lifetime_lazy_concurrent_runtime_init() {
713726
}
714727
source := lazy_concurrent_lifetime_init_source()
715728
for mode in ['none', 'boehm'] {
716-
res := run_program_with_gc(tmp_dir, 'closure_lifetime_lazy_init', source, mode)
717-
assert res.exit_code == 0, res.output
729+
assert_run_succeeds_or_missing_boehm(tmp_dir, 'closure_lifetime_lazy_init', source, mode)
718730
}
719731
}
720732

0 commit comments

Comments
 (0)