Skip to content

Commit

Permalink
tests: cargo only test couldn't run because of missing symbol compile…
Browse files Browse the repository at this point in the history
…d by cmake project
  • Loading branch information
OlivierLDff committed Mar 31, 2023
1 parent 25a9c53 commit 39e27c7
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/github-cxx-qt-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
# FIXME: many tests fail to link
# https://github.com/KDAB/cxx-qt/issues/111
# cxx_qt_lib_cargo_tests fails to run with a missing DLL error.
ctest_args: --exclude-regex '^(test_basic_cxx_only_cargo_tests|reuse_lint|cpp_clang_format|.*valgrind)$'
ctest_args: --exclude-regex '^(reuse_lint|cpp_clang_format|.*valgrind)$'
exe_suffix: .exe
qt_qpa_platform: windows
compiler_cache_path: C:\Users\runneradmin\AppData\Local\Mozilla\sccache\cache
Expand All @@ -106,7 +106,7 @@ jobs:
# FIXME: many tests fail to link
# https://github.com/KDAB/cxx-qt/issues/111
# cxx_qt_lib_cargo_tests fails to run with a missing DLL error.
ctest_args: --exclude-regex '^(test_basic_cxx_only_cargo_tests|reuse_lint|cpp_clang_format|.*valgrind)$'
ctest_args: --exclude-regex '^(reuse_lint|cpp_clang_format|.*valgrind)$'
exe_suffix: .exe
qt_qpa_platform: windows
compiler_cache_path: C:\Users\runneradmin\AppData\Local\Mozilla\sccache\cache
Expand Down
25 changes: 25 additions & 0 deletions tests/basic_cxx_only/cpp/cxx_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// clang-format off
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// clang-format on
// SPDX-FileContributor: Andrew Hayzen <[email protected]>
// SPDX-FileContributor: Gerhard de Clercq <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

#include "cxx_test.h"

namespace {
int hidden_num = 100;
}

int
get_cpp_number()
{
return hidden_num;
}

void
set_cpp_number(int num)
{
hidden_num = num;
}
3 changes: 3 additions & 0 deletions tests/basic_cxx_only/cpp/cxx_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@

int
get_cpp_number();

void
set_cpp_number(int num);
11 changes: 2 additions & 9 deletions tests/basic_cxx_only/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
#include <QtTest/QTest>

#include "cxx-qt-gen/ffi.cxx.h"

int hidden_num = 100;

int
get_cpp_number()
{
return hidden_num;
}
#include "cxx_test.h"

class CxxTest : public QObject
{
Expand All @@ -26,7 +19,7 @@ private Q_SLOTS:
void test_cxx_interaction()
{
QCOMPARE(get_numbers_sum(), 102);
hidden_num = 200;
set_cpp_number(200);
QCOMPARE(get_numbers_sum(), 202);
}
};
Expand Down
4 changes: 4 additions & 0 deletions tests/basic_cxx_only/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ fn main() {
.file("src/lib.rs")
.cc_builder(|cc| {
cc.include("../cpp");
// cxx_test.cpp need to be compiled by cargo rather than CMakeLists.txt,
// otherwise linking cargo tests fails because the symbols from those files are not found.
// This to make cargo only tests work.
cc.file("../cpp/cxx_test.cpp");
})
.build();
}
10 changes: 10 additions & 0 deletions tests/basic_cxx_only/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ mod ffi {
fn get_numbers_sum() -> i32 {
ffi::get_cpp_number() + 2
}

#[cfg(test)]
mod tests {
use super::ffi::get_cpp_number;

#[test]
fn test_get_numbers_sum() {
assert_eq!(get_cpp_number(), 100);
}
}

0 comments on commit 39e27c7

Please sign in to comment.