@@ -107,13 +107,16 @@ impl DocTestRunner {
107
107
{output}
108
108
109
109
mod __doctest_mod {{
110
- pub static mut BINARY_PATH: Option<std::path::PathBuf> = None;
110
+ use std::sync::OnceLock;
111
+ use std::path::PathBuf;
112
+
113
+ pub static BINARY_PATH: OnceLock<PathBuf> = OnceLock::new();
111
114
pub const RUN_OPTION: &str = \" *doctest-inner-test\" ;
112
115
pub const BIN_OPTION: &str = \" *doctest-bin-path\" ;
113
116
114
117
#[allow(unused)]
115
- pub fn get_doctest_path () -> Option<&'static std::path::Path > {{
116
- unsafe {{ self::BINARY_PATH.as_deref() }}
118
+ pub fn doctest_path () -> Option<&'static PathBuf > {{
119
+ self::BINARY_PATH.get()
117
120
}}
118
121
119
122
#[allow(unused)]
@@ -145,7 +148,9 @@ while let Some(arg) = args.next() {{
145
148
let Some(binary) = args.next() else {{
146
149
panic!(\" missing argument after `{{}}`\" , __doctest_mod::BIN_OPTION);
147
150
}};
148
- unsafe {{ crate::__doctest_mod::BINARY_PATH = Some(binary.into()); }}
151
+ if crate::__doctest_mod::BINARY_PATH.set(binary.into()).is_err() {{
152
+ panic!(\" `{{}}` option was used more than once\" , bin_marker.to_string_lossy());
153
+ }}
149
154
return std::process::Termination::report(test::test_main(test_args, Vec::from(TESTS), None));
150
155
}} else if arg == test_marker {{
151
156
let Some(nb_test) = args.next() else {{
@@ -254,7 +259,7 @@ test::StaticTestFn(
254
259
} else {
255
260
format!(
256
261
"
257
- if let Some(bin_path) = crate::__doctest_mod::get_doctest_path () {{
262
+ if let Some(bin_path) = crate::__doctest_mod::doctest_path () {{
258
263
test::assert_test_result(crate::__doctest_mod::doctest_runner(bin_path, {id}))
259
264
}} else {{
260
265
test::assert_test_result(self::main())
0 commit comments