diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-10-19 11:10:58 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-11-17 13:19:06 +0100 |
commit | 0641ed0eaa40499af7cacaeda10d7b845a14aaf9 (patch) | |
tree | f8d0b52a751071403dad2fbf50b5f3a53d602ed4 /tests/auto/environment | |
parent | fb47cfda115482351ef57092be58ba47b3276389 (diff) | |
download | qt-creator-0641ed0eaa40499af7cacaeda10d7b845a14aaf9.tar.gz |
change Environment::expandVariables() semantics
instead of being os-agnostic, interpret the os-native expansion style,
so it is consistent with proper (shell) command lines.
don't interpret quotes, as this function is meant for expanding isolated
filepaths, where nobody would expect quoting. instead, use the windows
style of simply not doing an expansion if a referenced variable is not
found, which should be good enough - it's rather unlikely that something
which happens to be an expansion of an existing variable is actually not
meant to be one.
Diffstat (limited to 'tests/auto/environment')
-rw-r--r-- | tests/auto/environment/environment.pro | 17 | ||||
-rw-r--r-- | tests/auto/environment/tst_environment.cpp | 107 |
2 files changed, 124 insertions, 0 deletions
diff --git a/tests/auto/environment/environment.pro b/tests/auto/environment/environment.pro new file mode 100644 index 0000000000..a39d91d66a --- /dev/null +++ b/tests/auto/environment/environment.pro @@ -0,0 +1,17 @@ +CONFIG += qtestlib testcase +TEMPLATE = app +CONFIG -= app_bundle +DEFINES += QTCREATOR_UTILS_LIB + +UTILS_PATH = ../../../src/libs/utils + +INCLUDEPATH += $$UTILS_PATH/.. + +SOURCES += \ + tst_environment.cpp \ + $$UTILS_PATH/environment.cpp +HEADERS += \ + $$UTILS_PATH/environment.h \ + $$UTILS_PATH/utils_global.h + +TARGET = tst_$$TARGET diff --git a/tests/auto/environment/tst_environment.cpp b/tests/auto/environment/tst_environment.cpp new file mode 100644 index 0000000000..26d4b752b9 --- /dev/null +++ b/tests/auto/environment/tst_environment.cpp @@ -0,0 +1,107 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include <utils/environment.h> + +#include <QtTest/QtTest> + +using namespace Utils; + +class tst_Environment : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void environment_data(); + void environment(); + +private: + Environment env; +}; + +void tst_Environment::initTestCase() +{ + env.set("word", "hi"); +} + +void tst_Environment::environment_data() +{ + QTest::addColumn<QString>("in"); + QTest::addColumn<QString>("out"); + + static const struct { + const char * const in; + const char * const out; + } vals[] = { +#ifdef Q_OS_WIN + { "", "" }, + { "hi", "hi" }, + { "hi%", "hi%" }, + { "hi% ho", "hi% ho" }, + { "hi%here ho", "hi%here ho" }, + { "hi%here%ho", "hi%here%ho" }, + { "hi%word%", "hihi" }, + { "hi%foo%word%", "hi%foohi" }, + { "%word%word%ho", "hiword%ho" }, + { "hi%word%x%word%ho", "hihixhiho" }, + { "hi%word%xx%word%ho", "hihixxhiho" }, + { "hi%word%%word%ho", "hihihiho" }, +#else + { "", "" }, + { "hi", "hi" }, + { "hi$", "hi$" }, + { "hi${", "hi${" }, + { "hi${word", "hi${word" }, + { "hi${word}", "hihi" }, + { "hi${word}ho", "hihiho" }, + { "hi$wo", "hi$wo" }, + { "hi$word", "hihi" }, + { "hi$word ho", "hihi ho" }, + { "$word", "hi" }, + { "hi${word}$word", "hihihi" }, +#endif + }; + + for (unsigned i = 0; i < sizeof(vals)/sizeof(vals[0]); i++) + QTest::newRow(vals[i].in) << QString::fromLatin1(vals[i].in) + << QString::fromLatin1(vals[i].out); +} + +void tst_Environment::environment() +{ + QFETCH(QString, in); + QFETCH(QString, out); + + QCOMPARE(env.expandVariables(in), out); +} + +QTEST_MAIN(tst_Environment) + +#include "tst_environment.moc" |