Skip to content

Commit 7571296

Browse files
committed
test: Support a new .skip_cpp test suffix.
Following the example of `.skip_warning_as_error`, this patch introduces a `.skip_cpp` suffix to skip the generation of `.cpp` files. This patch also simplifies the code. Ideally, we would create and implement a new trait offering an API like `is_cpp_skipped`, `is_warning_as_error_skipped`, and `normalize` (to remove all suffixes), but it's a little bit overkill for our needs right now.
1 parent 8e42a71 commit 7571296

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

tests/tests.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ fn compile(
130130
}
131131
}
132132

133+
const SKIP_CPP_SUFFIX: &'static str = ".skip_cpp";
134+
const SKIP_WARNING_AS_ERROR_SUFFIX: &'static str = ".skip_warning_as_error";
135+
133136
fn run_compile_test(
134137
cbindgen_path: &'static str,
135138
name: &'static str,
@@ -164,18 +167,14 @@ fn run_compile_test(
164167
}
165168
}
166169
};
167-
let skip_warning_as_error_suffix = ".skip_warning_as_error";
168-
let skip_warning_as_error_position = name.rfind(skip_warning_as_error_suffix);
169-
let skip_warning_as_error = skip_warning_as_error_position.is_some();
170-
let mut source_file = format!("{}.{}", name, &ext);
171-
172-
if skip_warning_as_error {
173-
source_file = format!(
174-
"{}.{}",
175-
&name[0..skip_warning_as_error_position.unwrap()],
176-
&ext
177-
);
178-
}
170+
171+
let skip_warning_as_error = name.rfind(SKIP_WARNING_AS_ERROR_SUFFIX).is_some();
172+
let skip_cpp = name.rfind(SKIP_CPP_SUFFIX).is_some();
173+
174+
let source_file = format!("{}.{}", &name, &ext)
175+
.replace(SKIP_CPP_SUFFIX, "")
176+
.replace(SKIP_WARNING_AS_ERROR_SUFFIX, "");
177+
179178
generated_file.push(source_file);
180179

181180
run_cbindgen(
@@ -196,7 +195,7 @@ fn run_compile_test(
196195
skip_warning_as_error,
197196
);
198197

199-
if language == Language::C && cpp_compat {
198+
if language == Language::C && cpp_compat && !skip_cpp {
200199
compile(
201200
&generated_file,
202201
&tests_path,
@@ -228,15 +227,20 @@ fn test_file(cbindgen_path: &'static str, name: &'static str, filename: &'static
228227
);
229228
}
230229
}
231-
run_compile_test(
232-
cbindgen_path,
233-
name,
234-
&test,
235-
tmp_dir,
236-
Language::Cxx,
237-
/* cpp_compat = */ false,
238-
None,
239-
);
230+
231+
let skip_cpp = name.rfind(SKIP_CPP_SUFFIX).is_some();
232+
233+
if !skip_cpp {
234+
run_compile_test(
235+
cbindgen_path,
236+
name,
237+
&test,
238+
tmp_dir,
239+
Language::Cxx,
240+
/* cpp_compat = */ false,
241+
None,
242+
);
243+
}
240244
}
241245

242246
macro_rules! test_file {

0 commit comments

Comments
 (0)