Skip to content

Commit c0a7819

Browse files
OlivierLDffBe-ing
authored andcommitted
cxx-qt-gen: fix test on windows (remove '\r')
On windows sometime the generated file, or the value returned from the clang-format call get \r in them. It is sane to remove all of them, to get consistency between unix and windows system for tests.
1 parent ffbfff3 commit c0a7819

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

.github/workflows/github-cxx-qt-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
# FIXME: many tests fail to link
9292
# https://github.com/KDAB/cxx-qt/issues/111
9393
# cxx_qt_lib_cargo_tests fails to run with a missing DLL error.
94-
ctest_args: --exclude-regex '^(cxx_qt_gen_cargo_tests|demo_threading_cargo_tests|example_qml.*|qml.*tests|test.*|reuse_lint|cpp_clang_format|.*valgrind|cxx_qt_lib_cargo_tests)$'
94+
ctest_args: --exclude-regex '^(demo_threading_cargo_tests|example_qml.*|qml.*tests|test.*|reuse_lint|cpp_clang_format|.*valgrind|cxx_qt_lib_cargo_tests)$'
9595
exe_suffix: .exe
9696
qt_qpa_platform: windows
9797
compiler_cache_path: C:\Users\runneradmin\AppData\Local\Mozilla\sccache\cache
@@ -106,7 +106,7 @@ jobs:
106106
# FIXME: many tests fail to link
107107
# https://github.com/KDAB/cxx-qt/issues/111
108108
# cxx_qt_lib_cargo_tests fails to run with a missing DLL error.
109-
ctest_args: --exclude-regex '^(cxx_qt_gen_cargo_tests|demo_threading_cargo_tests|example_qml.*|qml.*tests|test.*|reuse_lint|cpp_clang_format|.*valgrind|cxx_qt_lib_cargo_tests)$'
109+
ctest_args: --exclude-regex '^(demo_threading_cargo_tests|example_qml.*|qml.*tests|test.*|reuse_lint|cpp_clang_format|.*valgrind|cxx_qt_lib_cargo_tests)$'
110110
exe_suffix: .exe
111111
qt_qpa_platform: windows
112112
compiler_cache_path: C:\Users\runneradmin\AppData\Local\Mozilla\sccache\cache

crates/cxx-qt-gen/src/lib.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ mod tests {
7373
syn::parse2(tokens.into_token_stream()).unwrap()
7474
}
7575

76+
fn sanitize_code(mut code: String) -> String {
77+
code.retain(|c| c != '\r');
78+
code
79+
}
80+
7681
/// Helper for testing if a given input Rust file generates the expected C++ & Rust code
7782
/// This needs to be a macro rather than a function because include_str needs the file path at compile time.
7883
macro_rules! test_code_generation {
@@ -86,25 +91,31 @@ mod tests {
8691
let generated_cpp = GeneratedCppBlocks::from(&parser).unwrap();
8792
let (header, source) =
8893
if let CppFragment::Pair { header, source } = write_cpp(&generated_cpp) {
89-
(header, source)
94+
(sanitize_code(header), sanitize_code(source))
9095
} else {
9196
panic!("Expected CppFragment::Pair")
9297
};
9398
let expected_cpp_header =
94-
clang_format(include_str!(concat!("../test_outputs/", $file_stem, ".h"))).unwrap();
99+
clang_format(include_str!(concat!("../test_outputs/", $file_stem, ".h")))
100+
.map(sanitize_code)
101+
.unwrap();
95102
let expected_cpp_source = clang_format(include_str!(concat!(
96103
"../test_outputs/",
97104
$file_stem,
98105
".cpp"
99106
)))
107+
.map(sanitize_code)
100108
.unwrap();
101109
assert_str_eq!(header, expected_cpp_header);
102110
assert_str_eq!(source, expected_cpp_source);
103111

104112
let generated_rust = GeneratedRustBlocks::from(&parser).unwrap();
105-
let rust = format_rs_source(&write_rust(&generated_rust).to_string());
106-
let expected_rust_output =
107-
format_rs_source(include_str!(concat!("../test_outputs/", $file_stem, ".rs")));
113+
let rust = sanitize_code(format_rs_source(&write_rust(&generated_rust).to_string()));
114+
let expected_rust_output = sanitize_code(format_rs_source(include_str!(concat!(
115+
"../test_outputs/",
116+
$file_stem,
117+
".rs"
118+
))));
108119
assert_str_eq!(rust, expected_rust_output);
109120
};
110121
}

0 commit comments

Comments
 (0)