Skip to content
Browse files

Ensure launcher returns appropriate exit code

Fixes #35
  • Loading branch information...
1 parent f4c3356 commit 12090723b40d60430ddb77a5bf2cfedad4c56d10 @jcfr jcfr committed
View
22 Base/ctkAppLauncher.cpp
@@ -835,8 +835,8 @@ int ctkAppLauncher::processArguments()
if (this->Internal->ParsedArgs.value("launcher-generate-template").toBool())
{
- this->generateTemplate();
- return Self::ExitWithSuccess;
+ bool success = this->generateTemplate();
+ return success ? Self::ExitWithSuccess : Self::ExitWithError;
}
if (!this->Internal->processSplashPathArgument())
@@ -1013,7 +1013,7 @@ void ctkAppLauncher::startApplication()
}
// --------------------------------------------------------------------------
-void ctkAppLauncher::generateTemplate()
+bool ctkAppLauncher::generateTemplate()
{
this->Internal->ListOfPaths.clear();
this->Internal->ListOfPaths << "/home/john/app1"
@@ -1049,16 +1049,16 @@ void ctkAppLauncher::generateTemplate()
arg(this->Internal->LauncherDir).
arg(this->Internal->LauncherName);
- this->writeSettings(outputFile);
+ return this->writeSettings(outputFile);
}
// --------------------------------------------------------------------------
-bool ctkAppLauncher::configure()
+int ctkAppLauncher::configure()
{
if (!this->initialize())
{
this->Internal->exit(EXIT_FAILURE);
- return false;
+ return ctkAppLauncher::ExitWithError;
}
QString settingFileName = this->findSettingFile();
@@ -1074,12 +1074,12 @@ bool ctkAppLauncher::configure()
}
this->displayHelp(std::cerr);
this->Internal->exit(EXIT_FAILURE);
- return false;
+ return status;
}
else if (status == ctkAppLauncher::ExitWithSuccess)
{
this->Internal->exit(EXIT_SUCCESS);
- return false;
+ return status;
}
// Append 'unparsed arguments' to list of arguments that will be used to start the application.
@@ -1096,15 +1096,15 @@ bool ctkAppLauncher::configure()
}
this->Internal->ApplicationToLaunchArguments.append(unparsedArguments);
- return true;
+ return status;
}
// --------------------------------------------------------------------------
void ctkAppLauncher::startLauncher()
{
this->Internal->LauncherStarting = true;
- bool res = this->configure();
- if (!res)
+ int res = this->configure();
+ if (res != Self::Continue)
{
return;
}
View
7 Base/ctkAppLauncher.h
@@ -51,9 +51,10 @@ class ctkAppLauncher : public QObject
/// Configure the AppLauncher by first initializing the arguments (see
/// initialize()) and then read settings from ini file and parse arguments
/// arguments from command line.
- /// Return true if the application must be launched, false otherwise.
+ /// Return ProcessArgumentsStatus::Continue if the application must be launched,
+ /// or either ProcessArgumentsStatus::ExitWithError or ProcessArgumentsStatus::ExitWithSuccess otherwise.
/// \sa initialize(), setArguments(), startLauncher()
- bool configure();
+ int configure();
/// Set the launcher application and its arguments
/// \sa setArguments()
@@ -115,7 +116,7 @@ class ctkAppLauncher : public QObject
/// passed to the launcher, launcher settings, etc ...
bool verbose()const;
- void generateTemplate();
+ bool generateTemplate();
public slots:
View
12 Main.cpp
@@ -75,12 +75,14 @@ int appLauncherMain(int argc, char** argv)
QScopedPointer<ctkAppLauncher> appLauncher(new ctkAppLauncher);
appLauncher->setArguments(appArguments.arguments());
- bool exec = appLauncher->initialize(launcherFile.absoluteFilePath());
- exec = appLauncher->configure() && exec;
-
- if (!exec)
+ if (!appLauncher->initialize(launcherFile.absoluteFilePath()))
+ {
+ return EXIT_FAILURE;
+ }
+ int status = appLauncher->configure();
+ if (status != ctkAppLauncher::Continue)
{
- return EXIT_SUCCESS;
+ return status == ctkAppLauncher::ExitWithSuccess ? EXIT_SUCCESS : EXIT_FAILURE;
}
QScopedPointer<QCoreApplication> app;
View
6 Testing/CMake/AppLauncher-Param-TestLauncherNoSplash.cmake
@@ -23,12 +23,6 @@ size=1
set(PRINT_COMMAND 0)
# --------------------------------------------------------------------------
-# Delete settings file if it exists
-execute_process(
- COMMAND ${CMAKE_COMMAND} -E remove -f ${launcher}LauncherSettings.ini
- )
-
-# --------------------------------------------------------------------------
# TestNoSplashScreen - Check if launcher can work in no DISPLAY environment
set(command ${launcher_exe} --launcher-no-splash )
execute_process(
View
7 Testing/CMake/AppLauncher-TestNoLaunchSettingsNoLaunchParams.cmake
@@ -30,6 +30,11 @@ print_command_as_string("${command}")
if(NOT ${ev} STREQUAL ${expected_error_msg})
message(FATAL_ERROR "Since ${launcher_name} was started without any setting file or "
- " parameter, it should have failed to start.")
+ " parameter, it should have failed to start printing the expected "
+ " error message.")
endif()
+if(NOT ${rv} EQUAL 1)
+ message(FATAL_ERROR "Since ${launcher_name} was started without any setting file or "
+ " parameter, it should have failed to start with exit code of 1")
+endif()

0 comments on commit 1209072

Please sign in to comment.
Something went wrong with that request. Please try again.