Browse Source

Tests: Add some basic configure tests for the CMake GUI

Kyle Edwards 5 years ago
parent
commit
d6c051c126

+ 3 - 0
Tests/CMakeGUI/CMakeGUITest.cmake

@@ -109,3 +109,6 @@ run_cmake_gui_test(sourceBinaryArgs:noExistConfigExists
   ARGS
     "${CMakeGUITest_BINARY_DIR}/sourceBinaryArgs-noExistConfigExists/noexist"
   )
+
+run_cmake_gui_test(simpleConfigure:success)
+run_cmake_gui_test(simpleConfigure:fail)

+ 75 - 0
Tests/CMakeGUI/CMakeGUITest.cxx

@@ -2,8 +2,10 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "CMakeGUITest.h"
 
+#include "QCMake.h"
 #include <QApplication>
 #include <QEventLoop>
+#include <QMessageBox>
 #include <QSettings>
 #include <QString>
 #include <QStringList>
@@ -13,6 +15,9 @@
 
 #include "CMakeSetupDialog.h"
 
+#include "CatchShow.h"
+#include "FirstConfigure.h"
+
 namespace {
 void loopSleep(int msecs = 100)
 {
@@ -28,6 +33,44 @@ CMakeGUITest::CMakeGUITest(CMakeSetupDialog* window, QObject* parent)
 {
 }
 
+void CMakeGUITest::tryConfigure(int expectedResult, int timeout)
+{
+  auto* cmake = this->m_window->findChild<QCMakeThread*>()->cmakeInstance();
+
+  bool done = false;
+  CatchShow catchConfigure;
+  catchConfigure.setCallback<FirstConfigure>([&done](FirstConfigure* dialog) {
+    if (done) {
+      return;
+    }
+    done = true;
+
+    dialog->findChild<StartCompilerSetup*>()->setCurrentGenerator(
+      CMAKE_GENERATOR);
+    dialog->accept();
+  });
+
+  CatchShow catchMessages;
+  catchMessages.setCallback<QMessageBox>([](QMessageBox* box) {
+    if (box->text().contains("Build directory does not exist")) {
+      box->accept();
+    }
+
+    if (box->text().contains("Error in configuration process")) {
+      box->accept();
+    }
+  });
+
+  QSignalSpy configureDoneSpy(cmake, &QCMake::configureDone);
+  QVERIFY(configureDoneSpy.isValid());
+  QMetaObject::invokeMethod(
+    this->m_window, [this]() { this->m_window->ConfigureButton->click(); },
+    Qt::QueuedConnection);
+  QVERIFY(configureDoneSpy.wait(timeout));
+
+  QCOMPARE(configureDoneSpy, { { expectedResult } });
+}
+
 void CMakeGUITest::sourceBinaryArgs()
 {
   QFETCH(QString, sourceDir);
@@ -68,6 +111,38 @@ void CMakeGUITest::sourceBinaryArgs_data()
     << CMakeGUITest_BINARY_DIR "/sourceBinaryArgs-noExistConfigExists/build";
 }
 
+void CMakeGUITest::simpleConfigure()
+{
+  QFETCH(QString, sourceDir);
+  QFETCH(QString, binaryDir);
+  QFETCH(int, expectedResult);
+
+  this->m_window->SourceDirectory->setText(sourceDir);
+  this->m_window->BinaryDirectory->setCurrentText(binaryDir);
+
+  // Wait a bit for everything to update
+  loopSleep();
+
+  this->tryConfigure(expectedResult, 1000);
+}
+
+void CMakeGUITest::simpleConfigure_data()
+{
+  QTest::addColumn<QString>("sourceDir");
+  QTest::addColumn<QString>("binaryDir");
+  QTest::addColumn<int>("expectedResult");
+
+  QTest::newRow("success") << CMakeGUITest_BINARY_DIR
+    "/simpleConfigure-success/src"
+                           << CMakeGUITest_BINARY_DIR
+    "/simpleConfigure-success/build"
+                           << 0;
+  QTest::newRow("fail") << CMakeGUITest_BINARY_DIR "/simpleConfigure-fail/src"
+                        << CMakeGUITest_BINARY_DIR
+    "/simpleConfigure-fail/build"
+                        << -1;
+}
+
 void SetupDefaultQSettings()
 {
   QSettings::setDefaultFormat(QSettings::IniFormat);

+ 4 - 0
Tests/CMakeGUI/CMakeGUITest.h

@@ -15,7 +15,11 @@ public:
 private:
   CMakeSetupDialog* m_window = nullptr;
 
+  void tryConfigure(int expectedResult = 0, int timeout = 60000);
+
 private slots:
   void sourceBinaryArgs();
   void sourceBinaryArgs_data();
+  void simpleConfigure();
+  void simpleConfigure_data();
 };

+ 1 - 0
Tests/CMakeGUI/CMakeLists.txt

@@ -27,6 +27,7 @@ target_link_libraries(CMakeGUITest CMakeGUIMainLib CMakeGUITestLib Qt5::Core Qt5
 target_compile_definitions(CMakeGUITest PRIVATE
   "CMakeGUITest_SOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\""
   "CMakeGUITest_BINARY_DIR=\"${CMAKE_CURRENT_BINARY_DIR}\""
+  "CMAKE_GENERATOR=\"${CMAKE_GENERATOR}\""
   )
 
 add_test(NAME CMakeGUI COMMAND ${CMAKE_CMAKE_COMMAND}

+ 5 - 0
Tests/CMakeGUI/simpleConfigure-fail/CMakeLists.txt.in

@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 3.18)
+project(simpleConfigure-fail NONE)
+
+message(STATUS "This is a failed configure")
+message(FATAL_ERROR "Error")

+ 4 - 0
Tests/CMakeGUI/simpleConfigure-success/CMakeLists.txt.in

@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 3.18)
+project(simpleConfigure-success NONE)
+
+message(STATUS "This is a successful configure")