| // Copyright 2026 Google LLC | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // http://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, software | |
| // distributed under the License is distributed on an "AS IS" BASIS, | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| // See the License for the specific language governing permissions and | |
| // limitations under the License. | |
| use googletest::matchers; | |
| use googletest::prelude::*; | |
| use std::process::Command; | |
| use test_utils::EnvVars; | |
| #[gtest] | |
| fn test_fuzztests_are_registered_as_gtests(fixture: &EnvVars) { | |
| let target_binary_path = fixture.binary_path("fuzz_tests_as_gtests"); | |
| // Run the test binary with `--list` to list all registered tests. | |
| let output = Command::new(&target_binary_path) | |
| .arg("--list") | |
| .output() | |
| .expect("Failed to execute test binary"); | |
| assert!(output.status.success(), "Test binary failed to execute with --list"); | |
| let stdout = String::from_utf8_lossy(&output.stdout); | |
| // Verify that the expected fuzz tests are listed as regular tests. | |
| expect_that!(stdout, matchers::contains_substring("bool_fuzz_test: test")); | |
| expect_that!(stdout, matchers::contains_substring("multi_arg_fuzz_test: test")); | |
| } | |
| #[gtest] | |
| fn test_fuzztest_property_function_executes_in_gtest(fixture: &EnvVars) { | |
| let target_binary_path = fixture.binary_path("fuzz_tests_as_gtests"); | |
| // Run a fuzz test | |
| let output = Command::new(&target_binary_path) | |
| .arg("bool_fuzz_test") | |
| .arg("--nocapture") | |
| .output() | |
| .expect("Failed to execute test binary"); | |
| assert!(output.status.success(), "Test binary failed to execute `bool_fuzz_test`"); | |
| let stdout = String::from_utf8_lossy(&output.stdout); | |
| expect_that!(stdout, matchers::contains_substring("bool_fuzz_test property function ran...")); | |
| } | |
| #[gtest] | |
| fn test_panicking_fuzztest_prints_finding_report_in_smoke_test(fixture: &EnvVars) { | |
| let target_binary_path = fixture.binary_path("fuzztest_main"); | |
| let output = Command::new(&target_binary_path) | |
| .arg("find_bug_fuzz_test") | |
| .arg("--nocapture") | |
| .output() | |
| .expect("Failed to execute test binary"); | |
| expect_false!(output.status.success()); | |
| let stderr = String::from_utf8_lossy(&output.stderr); | |
| expect_that!(stderr, matchers::contains_substring("=== BUG FOUND!")); | |
| expect_that!( | |
| stderr, | |
| matchers::contains_substring( | |
| "Counterexample found for fuzztest_main::__fuzztest_mod__find_bug_fuzz_test::find_bug_fuzz_test." | |
| ) | |
| ); | |
| expect_that!( | |
| stderr, | |
| matchers::contains_substring("The test fails with input:\nargument 0: ") | |
| ); | |
| } |