summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-12-20 14:36:12 -0800
committerThiago Macieira <thiago.macieira@intel.com>2012-12-29 20:03:12 +0100
commitbe7238aa5372a72553a0ad6fef22bce3e03a8e7c (patch)
treeb556f2765a27331e3784f58c6cb451c8db1db99d
parent0c01e74470a1b467a9814fef979fe77fd3aeb0c4 (diff)
Remove the test-mode variables
One of the bugs I found during development was in the code handling the XDG data paths, which wasn't exercised during testing. So exercise it instead. Now the test-mode build will be exact the same as the normal code, except that it won't actually run the target executable. Change-Id: I829ed252836b2b581cd61c7dfab9d3061377e8f0 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/qtchooser/main.cpp51
-rw-r--r--tests/auto/qtchooser/testdata/config1/qtchooser/4.8.conf (renamed from tests/auto/qtchooser/testdata/config1/4.8.conf)0
-rw-r--r--tests/auto/qtchooser/testdata/config1/qtchooser/empty.conf (renamed from tests/auto/qtchooser/testdata/config1/empty.conf)0
-rw-r--r--tests/auto/qtchooser/testdata/config2/qtchooser/4.8.conf (renamed from tests/auto/qtchooser/testdata/config2/4.8.conf)0
-rw-r--r--tests/auto/qtchooser/testdata/config2/qtchooser/5.conf (renamed from tests/auto/qtchooser/testdata/config2/5.conf)0
-rw-r--r--tests/auto/qtchooser/testdata/config2/qtchooser/oneline.conf (renamed from tests/auto/qtchooser/testdata/config2/oneline.conf)0
-rw-r--r--tests/auto/qtchooser/testdata/default/qtchooser/default.conf (renamed from tests/auto/qtchooser/testdata/default/default.conf)0
-rw-r--r--tests/auto/qtchooser/tst_qtchooser.cpp6
8 files changed, 25 insertions, 32 deletions
diff --git a/src/qtchooser/main.cpp b/src/qtchooser/main.cpp
index a7b3599..51e746b 100644
--- a/src/qtchooser/main.cpp
+++ b/src/qtchooser/main.cpp
@@ -72,7 +72,6 @@
using namespace std;
-static bool testMode = false;
static const char *argv0;
enum Mode {
RunTool,
@@ -138,16 +137,16 @@ int ToolWrapper::runTool(const string &targetSdk, const string &targetTool, char
string tool = sdk.toolsPath + PATH_SEP + targetTool;
argv[0] = &tool[0];
- if (testMode) {
- while (*argv)
- printf("%s\n", *argv++);
- return 0;
- }
-
+#ifdef QTCHOOSER_TEST_MODE
+ while (*argv)
+ printf("%s\n", *argv++);
+ return 0;
+#else
execv(argv[0], argv);
fprintf(stderr, "%s: could not exec '%s': %s\n",
argv0, argv[0], strerror(errno));
return 1;
+#endif
}
static vector<string> stringSplit(const char *source)
@@ -178,26 +177,24 @@ static vector<string> stringSplit(const char *source)
vector<string> ToolWrapper::searchPaths() const
{
vector<string> paths;
- if (testMode) {
- return stringSplit(getenv("QTCHOOSER_PATHS"));
- } else {
- // search the XDG config location directories
- const char *globalDirs = getenv("XDG_CONFIG_DIRS");
- paths = stringSplit(!globalDirs || !*globalDirs ? "/etc/xdg" : globalDirs);
-
- string localDir;
- const char *localDirEnv = getenv("XDG_CONFIG_HOME");
- if (localDirEnv && *localDirEnv) {
- localDir = localDirEnv;
- } else {
- localDir = getenv("HOME"); // accept empty $HOME too
- localDir += "/.config";
- }
- paths.push_back(localDir);
- for (vector<string>::iterator it = paths.begin(); it != paths.end(); ++it)
- *it += "/qtchooser/";
+ // search the XDG config location directories
+ const char *globalDirs = getenv("XDG_CONFIG_DIRS");
+ paths = stringSplit(!globalDirs || !*globalDirs ? "/etc/xdg" : globalDirs);
+
+ string localDir;
+ const char *localDirEnv = getenv("XDG_CONFIG_HOME");
+ if (localDirEnv && *localDirEnv) {
+ localDir = localDirEnv;
+ } else {
+ localDir = getenv("HOME"); // accept empty $HOME too
+ localDir += "/.config";
}
+ paths.push_back(localDir);
+
+ for (vector<string>::iterator it = paths.begin(); it != paths.end(); ++it)
+ *it += "/qtchooser/";
+
return paths;
}
@@ -307,10 +304,6 @@ int main(int argc, char **argv)
const char *targetSdk = getenv("QT_SELECT");
const char *targetTool = getenv("QTCHOOSER_RUNTOOL");
-#ifdef QTCHOOSER_TEST_MODE
- testMode = atoi(getenv("QTCHOOSER_TESTMODE")) > 0;
-#endif
-
// if the target tool wasn't set in the environment, use argv[0]
if (!targetTool || !*targetTool)
targetTool = argv0;
diff --git a/tests/auto/qtchooser/testdata/config1/4.8.conf b/tests/auto/qtchooser/testdata/config1/qtchooser/4.8.conf
index 54153b7..54153b7 100644
--- a/tests/auto/qtchooser/testdata/config1/4.8.conf
+++ b/tests/auto/qtchooser/testdata/config1/qtchooser/4.8.conf
diff --git a/tests/auto/qtchooser/testdata/config1/empty.conf b/tests/auto/qtchooser/testdata/config1/qtchooser/empty.conf
index 8b13789..8b13789 100644
--- a/tests/auto/qtchooser/testdata/config1/empty.conf
+++ b/tests/auto/qtchooser/testdata/config1/qtchooser/empty.conf
diff --git a/tests/auto/qtchooser/testdata/config2/4.8.conf b/tests/auto/qtchooser/testdata/config2/qtchooser/4.8.conf
index 71d3255..71d3255 100644
--- a/tests/auto/qtchooser/testdata/config2/4.8.conf
+++ b/tests/auto/qtchooser/testdata/config2/qtchooser/4.8.conf
diff --git a/tests/auto/qtchooser/testdata/config2/5.conf b/tests/auto/qtchooser/testdata/config2/qtchooser/5.conf
index dcb18d5..dcb18d5 100644
--- a/tests/auto/qtchooser/testdata/config2/5.conf
+++ b/tests/auto/qtchooser/testdata/config2/qtchooser/5.conf
diff --git a/tests/auto/qtchooser/testdata/config2/oneline.conf b/tests/auto/qtchooser/testdata/config2/qtchooser/oneline.conf
index bdf113b..bdf113b 100644
--- a/tests/auto/qtchooser/testdata/config2/oneline.conf
+++ b/tests/auto/qtchooser/testdata/config2/qtchooser/oneline.conf
diff --git a/tests/auto/qtchooser/testdata/default/default.conf b/tests/auto/qtchooser/testdata/default/qtchooser/default.conf
index 4ad8426..4ad8426 100644
--- a/tests/auto/qtchooser/testdata/default/default.conf
+++ b/tests/auto/qtchooser/testdata/default/qtchooser/default.conf
diff --git a/tests/auto/qtchooser/tst_qtchooser.cpp b/tests/auto/qtchooser/tst_qtchooser.cpp
index 9e5bf93..345ae2c 100644
--- a/tests/auto/qtchooser/tst_qtchooser.cpp
+++ b/tests/auto/qtchooser/tst_qtchooser.cpp
@@ -97,8 +97,8 @@ tst_ToolChooser::tst_ToolChooser()
QString testData = QFINDTESTDATA("testdata");
pathsWithDefault = testData + "/config1" LIST_SEP +
testData + "/config2";
- testModeEnvironment.insert("QTCHOOSER_PATHS", pathsWithDefault);
- testModeEnvironment.insert("QTCHOOSER_TESTMODE", "1");
+ testModeEnvironment.insert("XDG_CONFIG_HOME", "/dev/null");
+ testModeEnvironment.insert("XDG_CONFIG_DIRS", pathsWithDefault);
testModeEnvironment.insert("QT_SELECT", "4.8");
pathsWithDefault.prepend(testData + "/default" LIST_SEP);
@@ -298,7 +298,7 @@ void tst_ToolChooser::defaultQt()
QProcessEnvironment env = testModeEnvironment;
env.remove("QT_SELECT");
if (withDefault)
- env.insert("QTCHOOSER_PATHS", pathsWithDefault);
+ env.insert("XDG_CONFIG_DIRS", pathsWithDefault);
QScopedPointer<QProcess> proc(execute(QStringList() << "-print-qmake", env));
QVERIFY(proc);