From 6c4d458599fab991fa332e9b42aba647a2925755 Mon Sep 17 00:00:00 2001 From: saker Date: Mon, 15 Jan 2024 17:19:33 -0500 Subject: [PATCH] Migrate to CTest (#7062) --- .github/workflows/build.yml | 20 +++++----- include/lmms_math.h | 7 ++-- tests/CMakeLists.txt | 49 ++++++++++++------------ tests/QTestSuite.cpp | 19 --------- tests/QTestSuite.h | 21 ---------- tests/main.cpp | 24 ------------ tests/src/core/ArrayVectorTest.cpp | 10 ++--- tests/src/core/AutomatableModelTest.cpp | 23 +++++++++-- tests/src/core/MathTest.cpp | 11 +++--- tests/src/core/ProjectVersionTest.cpp | 9 +++-- tests/src/core/RelativePathsTest.cpp | 13 ++++--- tests/src/tracks/AutomationTrackTest.cpp | 15 ++++++-- 12 files changed, 92 insertions(+), 129 deletions(-) delete mode 100644 tests/QTestSuite.cpp delete mode 100644 tests/QTestSuite.h delete mode 100644 tests/main.cpp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5fe1ec7bf72..b08c3ba20a8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,10 +45,10 @@ jobs: cmake .. $CMAKE_OPTS -DCMAKE_INSTALL_PREFIX=./install - name: Build run: cmake --build build - - name: Build tests - run: cmake --build build --target tests - name: Run tests - run: build/tests/tests + run: | + cd build/tests + ctest --output-on-failure -j2 - name: Package run: | cmake --build build --target install @@ -123,10 +123,10 @@ jobs: -DUSE_WERROR=OFF - name: Build run: cmake --build build - - name: Build tests - run: cmake --build build --target tests - name: Run tests - run: build/tests/tests + run: | + cd build/tests + ctest --output-on-failure -j3 - name: Package run: | cmake --build build --target install @@ -194,8 +194,6 @@ jobs: ../cmake/build_win${{ matrix.arch }}.sh - name: Build run: cmake --build build - - name: Build tests - run: cmake --build build --target tests - name: Package run: cmake --build build --target package - name: Upload artifacts @@ -286,8 +284,10 @@ jobs: ${{ steps.cache-deps.outputs.cache-hit == 'true' && 'NO' || 'YES' }} - name: Build run: cmake --build build - - name: Build tests - run: cmake --build build --target tests + - name: Run tests + run: | + cd build/tests + ctest --output-on-failure -j2 - name: Package run: cmake --build build --target package - name: Upload artifacts diff --git a/include/lmms_math.h b/include/lmms_math.h index ea0a75581e8..f6455d6931f 100644 --- a/include/lmms_math.h +++ b/include/lmms_math.h @@ -25,12 +25,13 @@ #ifndef LMMS_MATH_H #define LMMS_MATH_H +#include +#include +#include #include + #include "lmms_constants.h" #include "lmmsconfig.h" -#include - -#include namespace lmms { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ddf9e29621b..9a609922c2c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,34 +1,33 @@ -INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}") -INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}") -INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include") -INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}") -INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}/src") +include(CTest) -SET(CMAKE_CXX_STANDARD 17) - -SET(CMAKE_AUTOMOC ON) - -# FIXME: remove this once we export include directories for LMMS -IF(LMMS_BUILD_APPLE) -INCLUDE_DIRECTORIES("/usr/local/include") -ENDIF() - -ADD_EXECUTABLE(tests - EXCLUDE_FROM_ALL - main.cpp - QTestSuite.cpp - $ +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) +set(LMMS_TESTS src/core/ArrayVectorTest.cpp src/core/AutomatableModelTest.cpp src/core/MathTest.cpp src/core/ProjectVersionTest.cpp src/core/RelativePathsTest.cpp - src/tracks/AutomationTrackTest.cpp ) -TARGET_COMPILE_DEFINITIONS(tests - PRIVATE $ -) -TARGET_LINK_LIBRARIES(tests ${QT_LIBRARIES} ${QT_QTTEST_LIBRARY}) -TARGET_LINK_LIBRARIES(tests ${LMMS_REQUIRED_LIBS}) + +foreach(LMMS_TEST_SRC IN LISTS LMMS_TESTS) + # TODO CMake 3.20: Use cmake_path + get_filename_component(LMMS_TEST_NAME ${LMMS_TEST_SRC} NAME_WE) + + add_executable(${LMMS_TEST_NAME} $ ${LMMS_TEST_SRC}) + add_test(NAME ${LMMS_TEST_NAME} COMMAND ${LMMS_TEST_NAME}) + + # TODO CMake 3.12: Propagate usage requirements by linking to lmmsobjs + target_include_directories(${LMMS_TEST_NAME} PRIVATE $) + + target_link_libraries(${LMMS_TEST_NAME} PRIVATE + ${LMMS_REQUIRED_LIBS} + ${QT_LIBRARIES} + ${QT_QTTEST_LIBRARY} + ) + + target_compile_features(${LMMS_TEST_NAME} PRIVATE cxx_std_17) + target_compile_definitions(${LMMS_TEST_NAME} PRIVATE $) +endforeach() diff --git a/tests/QTestSuite.cpp b/tests/QTestSuite.cpp deleted file mode 100644 index a5a49fd20b1..00000000000 --- a/tests/QTestSuite.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "QTestSuite.h" - -QList QTestSuite::m_suites; - -QTestSuite::QTestSuite(QObject *parent) : QObject(parent) -{ - m_suites << this; -} - -QTestSuite::~QTestSuite() -{ - m_suites.removeAll(this); -} - -QList QTestSuite::suites() -{ - return m_suites; -} - diff --git a/tests/QTestSuite.h b/tests/QTestSuite.h deleted file mode 100644 index 6cd27f5aa5a..00000000000 --- a/tests/QTestSuite.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef QTESTSUITE_H -#define QTESTSUITE_H - -#include -#include -#include - -class QTestSuite : public QObject -{ - Q_OBJECT -public: - explicit QTestSuite(QObject *parent = 0); - ~QTestSuite() override; - - static QList suites(); - -private: - static QList m_suites; -}; - -#endif // QTESTSUITE_H diff --git a/tests/main.cpp b/tests/main.cpp deleted file mode 100644 index b95f211d4e2..00000000000 --- a/tests/main.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "QTestSuite.h" - -#include - -#include - -#include "Engine.h" - -int main(int argc, char* argv[]) -{ - new QCoreApplication(argc, argv); - lmms::Engine::init(true); - - int numsuites = QTestSuite::suites().size(); - qDebug() << ">> Will run" << numsuites << "test suites"; - int failed = 0; - for (QTestSuite*& suite : QTestSuite::suites()) - { - if (QTest::qExec(suite, argc, argv) != 0) { ++failed; } - } - qDebug() << "<<" << failed << "out of"< +#include #include #include -#include "QTestSuite.h" - using lmms::ArrayVector; struct ShouldNotConstruct @@ -59,10 +59,9 @@ struct DestructorCheck bool* destructed; }; -class ArrayVectorTest : QTestSuite +class ArrayVectorTest : public QObject { Q_OBJECT - private slots: void defaultConstructorTest() { @@ -826,6 +825,7 @@ private slots: QVERIFY(!(e != v)); QVERIFY(g != v); } -} ArrayVectorTests; +}; +QTEST_GUILESS_MAIN(ArrayVectorTest) #include "ArrayVectorTest.moc" diff --git a/tests/src/core/AutomatableModelTest.cpp b/tests/src/core/AutomatableModelTest.cpp index 78b9069b5e8..6e8a28116d8 100644 --- a/tests/src/core/AutomatableModelTest.cpp +++ b/tests/src/core/AutomatableModelTest.cpp @@ -22,15 +22,16 @@ * */ -#include "QTestSuite.h" +#include #include "AutomatableModel.h" #include "ComboBoxModel.h" +#include "Engine.h" -class AutomatableModelTest : QTestSuite +class AutomatableModelTest : public QObject { Q_OBJECT - +public: bool m1Changed, m2Changed; void resetChanged() { m1Changed = m2Changed = false; } @@ -41,6 +42,19 @@ private slots: // helper slots private slots: // tests //! Test that upcast and exact casts work, //! but no downcast or any other casts + + void initTestCase() + { + using namespace lmms; + Engine::init(true); + } + + void cleanupTestCase() + { + using namespace lmms; + Engine::destroy(); + } + void CastTests() { using namespace lmms; @@ -100,6 +114,7 @@ private slots: // tests QVERIFY(m2.value()); QVERIFY(!m3.value()); } -} AutomatableModelTests; +}; +QTEST_GUILESS_MAIN(AutomatableModelTest) #include "AutomatableModelTest.moc" diff --git a/tests/src/core/MathTest.cpp b/tests/src/core/MathTest.cpp index 2b6404cfd5c..00694c44fba 100644 --- a/tests/src/core/MathTest.cpp +++ b/tests/src/core/MathTest.cpp @@ -22,13 +22,13 @@ * */ -#include "QTestSuite.h" +#include +#include +#include #include "lmms_math.h" -#include - -class MathTest : QTestSuite +class MathTest : public QObject { Q_OBJECT private slots: @@ -48,6 +48,7 @@ private slots: QCOMPARE(numDigitsAsInt(900000000), 9); QCOMPARE(numDigitsAsInt(-900000000), 10); } -} MathTests; +}; +QTEST_GUILESS_MAIN(MathTest) #include "MathTest.moc" diff --git a/tests/src/core/ProjectVersionTest.cpp b/tests/src/core/ProjectVersionTest.cpp index 387d9005660..03b6895414b 100644 --- a/tests/src/core/ProjectVersionTest.cpp +++ b/tests/src/core/ProjectVersionTest.cpp @@ -22,11 +22,11 @@ * */ -#include "QTestSuite.h" - #include "ProjectVersion.h" -class ProjectVersionTest : QTestSuite +#include + +class ProjectVersionTest : public QObject { Q_OBJECT private slots: @@ -75,6 +75,7 @@ private slots: //An identifier of the form "-x" is non-numeric, not negative QVERIFY(ProjectVersion("1.0.0-alpha.-1") > "1.0.0-alpha.1"); } -} ProjectVersionTests; +}; +QTEST_GUILESS_MAIN(ProjectVersionTest) #include "ProjectVersionTest.moc" diff --git a/tests/src/core/RelativePathsTest.cpp b/tests/src/core/RelativePathsTest.cpp index 3b5d023d041..089ab2e8ae0 100644 --- a/tests/src/core/RelativePathsTest.cpp +++ b/tests/src/core/RelativePathsTest.cpp @@ -22,15 +22,15 @@ * */ -#include "QTestSuite.h" +#include +#include +#include #include "ConfigManager.h" -#include "SampleBuffer.h" #include "PathUtil.h" +#include "SampleBuffer.h" -#include - -class RelativePathsTest : QTestSuite +class RelativePathsTest : public QObject { Q_OBJECT private slots: @@ -66,6 +66,7 @@ private slots: QCOMPARE(PathUtil::toAbsolute(""), empty); QCOMPARE(PathUtil::toShortestRelative(""), empty); } -} RelativePathTests; +}; +QTEST_GUILESS_MAIN(RelativePathsTest) #include "RelativePathsTest.moc" diff --git a/tests/src/tracks/AutomationTrackTest.cpp b/tests/src/tracks/AutomationTrackTest.cpp index f0150807599..b4f6effd9e4 100644 --- a/tests/src/tracks/AutomationTrackTest.cpp +++ b/tests/src/tracks/AutomationTrackTest.cpp @@ -22,7 +22,7 @@ * */ -#include "QTestSuite.h" +#include #include "QCoreApplication" @@ -39,12 +39,20 @@ #include "Engine.h" #include "Song.h" -class AutomationTrackTest : QTestSuite +class AutomationTrackTest : public QObject { Q_OBJECT private slots: void initTestCase() { + using namespace lmms; + Engine::init(true); + } + + void cleanupTestCase() + { + using namespace lmms; + Engine::destroy(); } void testClipLinear() @@ -232,6 +240,7 @@ private slots: QCOMPARE(song->automatedValuesAt(0)[&model], 50.0f); } -} AutomationTrackTest; +}; +QTEST_GUILESS_MAIN(AutomationTrackTest) #include "AutomationTrackTest.moc"