diff options
author | 2025-02-11 14:58:07 -0800 | |
---|---|---|
committer | 2025-02-12 10:36:48 -0800 | |
commit | 90607e9056f6ff4cec2447fdd7a8b252d67ffde7 (patch) | |
tree | d4e244bc76e8e13a8438bcd921fd9003bce46730 /rust/bindgen_test.go | |
parent | d8db8faba62a3cb77f75294e96deda9e53c15786 (diff) |
Don't panic in ModuleForTests and friends
Panicking in ModuleForTests and similar test helper functions was
a mistake. Go's test runner stops running tests as soon as any
test panics, which means debugging multiple tests panicking requires
rerunning all the tests after fixing each panic to find the next
one. Pass the *testing.T into ModuleForTests and friends so that
it can call t.Fatalf instead.
Test: all soong tests pass
Change-Id: I5d0f2424eaf04fb795079e6d1e4b9469d8c7033c
Diffstat (limited to 'rust/bindgen_test.go')
-rw-r--r-- | rust/bindgen_test.go | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/rust/bindgen_test.go b/rust/bindgen_test.go index 2b7362f08..267fb1cba 100644 --- a/rust/bindgen_test.go +++ b/rust/bindgen_test.go @@ -67,10 +67,10 @@ func TestRustBindgen(t *testing.T) { cflags: ["--default-flag"], } `) - libbindgen := ctx.ModuleForTests("libbindgen", "android_arm64_armv8-a_source").Output("bindings.rs") - libbindgenStatic := ctx.ModuleForTests("libbindgen_staticlib", "android_arm64_armv8-a_source").Output("bindings.rs") - libbindgenHeader := ctx.ModuleForTests("libbindgen_headerlib", "android_arm64_armv8-a_source").Output("bindings.rs") - libbindgenHeaderModule := ctx.ModuleForTests("libbindgen_headerlib", "android_arm64_armv8-a_source").Module().(*Module) + libbindgen := ctx.ModuleForTests(t, "libbindgen", "android_arm64_armv8-a_source").Output("bindings.rs") + libbindgenStatic := ctx.ModuleForTests(t, "libbindgen_staticlib", "android_arm64_armv8-a_source").Output("bindings.rs") + libbindgenHeader := ctx.ModuleForTests(t, "libbindgen_headerlib", "android_arm64_armv8-a_source").Output("bindings.rs") + libbindgenHeaderModule := ctx.ModuleForTests(t, "libbindgen_headerlib", "android_arm64_armv8-a_source").Module().(*Module) // Ensure that the flags are present and escaped if !strings.Contains(libbindgen.Args["flags"], "'--bindgen-flag.*'") { t.Errorf("missing bindgen flags in rust_bindgen rule: flags %#v", libbindgen.Args["flags"]) @@ -113,7 +113,7 @@ func TestRustBindgenCustomBindgen(t *testing.T) { } `) - libbindgen := ctx.ModuleForTests("libbindgen", "android_arm64_armv8-a_source").Output("bindings.rs") + libbindgen := ctx.ModuleForTests(t, "libbindgen", "android_arm64_armv8-a_source").Output("bindings.rs") // The rule description should contain the custom binary name rather than bindgen, so checking the description // should be sufficient. @@ -155,8 +155,8 @@ func TestRustBindgenStdVersions(t *testing.T) { } `) - libbindgen_cstd := ctx.ModuleForTests("libbindgen_cstd", "android_arm64_armv8-a_source").Output("bindings.rs") - libbindgen_cppstd := ctx.ModuleForTests("libbindgen_cppstd", "android_arm64_armv8-a_source").Output("bindings.rs") + libbindgen_cstd := ctx.ModuleForTests(t, "libbindgen_cstd", "android_arm64_armv8-a_source").Output("bindings.rs") + libbindgen_cppstd := ctx.ModuleForTests(t, "libbindgen_cppstd", "android_arm64_armv8-a_source").Output("bindings.rs") if !strings.Contains(libbindgen_cstd.Args["cflags"], "-std=foo") { t.Errorf("c_std value not passed in to rust_bindgen as a clang flag") @@ -216,7 +216,7 @@ func TestBindgenFlagFile(t *testing.T) { ], } `) - libbindgen := ctx.ModuleForTests("libbindgen", "android_arm64_armv8-a_source").Output("bindings.rs") + libbindgen := ctx.ModuleForTests(t, "libbindgen", "android_arm64_armv8-a_source").Output("bindings.rs") if !strings.Contains(libbindgen.Args["flagfiles"], "/dev/null") { t.Errorf("missing /dev/null in rust_bindgen rule: flags %#v", libbindgen.Args["flagfiles"]) @@ -246,7 +246,7 @@ func TestBindgenHandleStaticInlining(t *testing.T) { include_dirs: ["src/"], } `) - libbindgen := ctx.ModuleForTests("libbindgen", "android_arm64_armv8-a_source").Output("bindings.rs") + libbindgen := ctx.ModuleForTests(t, "libbindgen", "android_arm64_armv8-a_source").Output("bindings.rs") // Make sure the flag to support `static inline` functions is present if !strings.Contains(libbindgen.Args["flags"], "--wrap-static-fns") { t.Errorf("missing flag to handle static inlining in rust_bindgen rule: flags %#v", libbindgen.Args["flags"]) |