From 15400d94664f93dc22f71802eb72c34c52e371ac Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 26 Aug 2011 17:36:55 +1000 Subject: Send error messages to stderr rather than stdout The commit changes printf's that output error and warning messages to send their text to the stderr stream. Non-error output, such as that produced by passing the -help option to a test, still goes to stdout. Change-Id: Iea4d62451e3e7e84c654859cb09ea7e717511d13 Reviewed-on: http://codereview.qt.nokia.com/3636 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qabstracttestlogger.cpp | 2 +- src/testlib/qtestcase.cpp | 66 ++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 34 deletions(-) (limited to 'src/testlib') diff --git a/src/testlib/qabstracttestlogger.cpp b/src/testlib/qabstracttestlogger.cpp index a5651317e7..d71addb655 100644 --- a/src/testlib/qabstracttestlogger.cpp +++ b/src/testlib/qabstracttestlogger.cpp @@ -76,7 +76,7 @@ void QAbstractTestLogger::startLogging(const char *filename) stream = ::fopen(filename, "wt"); if (!stream) { #endif - printf("Unable to open file for logging: %s", filename); + fprintf(stderr, "Unable to open file for logging: %s", filename); ::exit(1); } } diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 9c50257b44..d71fb90254 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1018,12 +1018,12 @@ Q_TESTLIB_EXPORT bool printAvailableFunctions = false; Q_TESTLIB_EXPORT QStringList testFunctions; Q_TESTLIB_EXPORT QStringList testTags; -static void qPrintTestSlots() +static void qPrintTestSlots(FILE *stream) { for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) { QMetaMethod sl = QTest::currentTestObject->metaObject()->method(i); if (isValidSlot(sl)) - printf("%s\n", sl.signature()); + fprintf(stream, "%s\n", sl.signature()); } } @@ -1032,7 +1032,7 @@ static int qToInt(char *str) char *pEnd; int l = (int)strtol(str, &pEnd, 10); if (*pEnd != 0) { - printf("Invalid numeric parameter: '%s'\n", str); + fprintf(stderr, "Invalid numeric parameter: '%s'\n", str); exit(1); } return l; @@ -1100,7 +1100,7 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) if (qml) { QTest::printAvailableFunctions = true; } else { - qPrintTestSlots(); + qPrintTestSlots(stdout); exit(0); } } else if(strcmp(argv[i], "-xunitxml") == 0){ @@ -1121,35 +1121,35 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) QSignalDumper::startDump(); } else if (strcmp(argv[i], "-o") == 0) { if (i + 1 >= argc) { - printf("-o needs an extra parameter specifying the filename\n"); + fprintf(stderr, "-o needs an extra parameter specifying the filename\n"); exit(1); } else { QTestLog::redirectOutput(argv[++i]); } } else if (strcmp(argv[i], "-eventdelay") == 0) { if (i + 1 >= argc) { - printf("-eventdelay needs an extra parameter to indicate the delay(ms)\n"); + fprintf(stderr, "-eventdelay needs an extra parameter to indicate the delay(ms)\n"); exit(1); } else { QTest::eventDelay = qToInt(argv[++i]); } } else if (strcmp(argv[i], "-keydelay") == 0) { if (i + 1 >= argc) { - printf("-keydelay needs an extra parameter to indicate the delay(ms)\n"); + fprintf(stderr, "-keydelay needs an extra parameter to indicate the delay(ms)\n"); exit(1); } else { QTest::keyDelay = qToInt(argv[++i]); } } else if (strcmp(argv[i], "-mousedelay") == 0) { if (i + 1 >= argc) { - printf("-mousedelay needs an extra parameter to indicate the delay(ms)\n"); + fprintf(stderr, "-mousedelay needs an extra parameter to indicate the delay(ms)\n"); exit(1); } else { QTest::mouseDelay = qToInt(argv[++i]); } } else if (strcmp(argv[i], "-maxwarnings") == 0) { if (i + 1 >= argc) { - printf("-maxwarnings needs an extra parameter with the amount of warnings\n"); + fprintf(stderr, "-maxwarnings needs an extra parameter with the amount of warnings\n"); exit(1); } else { QTestLog::setMaxWarnings(qToInt(argv[++i])); @@ -1166,10 +1166,10 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) if (QFileInfo(QDir::currentPath()).isWritable()) { QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::CallgrindParentProcess); } else { - printf("WARNING: Current directory not writable. Using the walltime measurer.\n"); + fprintf(stderr, "WARNING: Current directory not writable. Using the walltime measurer.\n"); } else { - printf("WARNING: Valgrind not found or too old. Make sure it is installed and in your path. " + fprintf(stderr, "WARNING: Valgrind not found or too old. Make sure it is installed and in your path. " "Using the walltime measurer.\n"); } } else if (strcmp(argv[i], "-callgrindchild") == 0) { // "private" option @@ -1194,28 +1194,28 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) QTest::seed = longSeed; } if (!argumentOk) { - printf("-seed needs an extra positive integer parameter to specify the seed\n"); + fprintf(stderr, "-seed needs an extra positive integer parameter to specify the seed\n"); exit(1); } else { QTest::seedSet = true; } } else if (strcmp(argv[i], "-minimumvalue") == 0) { if (i + 1 >= argc) { - printf("-minimumvalue needs an extra parameter to indicate the minimum time(ms)\n"); + fprintf(stderr, "-minimumvalue needs an extra parameter to indicate the minimum time(ms)\n"); exit(1); } else { QBenchmarkGlobalData::current->walltimeMinimum = qToInt(argv[++i]); } } else if (strcmp(argv[i], "-iterations") == 0) { if (i + 1 >= argc) { - printf("-iterations needs an extra parameter to indicate the number of iterations\n"); + fprintf(stderr, "-iterations needs an extra parameter to indicate the number of iterations\n"); exit(1); } else { QBenchmarkGlobalData::current->iterationCount = qToInt(argv[++i]); } } else if (strcmp(argv[i], "-median") == 0) { if (i + 1 >= argc) { - printf("-median needs an extra parameter to indicate the number of median iterations\n"); + fprintf(stderr, "-median needs an extra parameter to indicate the number of median iterations\n"); exit(1); } else { QBenchmarkGlobalData::current->medianIterationCount = qToInt(argv[++i]); @@ -1230,23 +1230,23 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) } else if (strcmp(argv[i], "-graphicssystem") == 0) { // do nothing if (i + 1 >= argc) { - printf("-graphicssystem needs an extra parameter specifying the graphics system\n"); + fprintf(stderr, "-graphicssystem needs an extra parameter specifying the graphics system\n"); exit(1); } else { ++i; } } else if (argv[i][0] == '-') { - printf("Unknown option: '%s'\n\n%s", argv[i], testOptions); + fprintf(stderr, "Unknown option: '%s'\n\n%s", argv[i], testOptions); if (qml) { - printf ("\nqmltest related options:\n" - " -import : Specify an import directory.\n" - " -input : Specify the root directory for test cases.\n" - " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" - ); + fprintf(stderr, "\nqmltest related options:\n" + " -import : Specify an import directory.\n" + " -input : Specify the root directory for test cases.\n" + " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" + ); } - printf("\n" - " -help : This help\n"); + fprintf(stderr, "\n" + " -help : This help\n"); exit(1); } else if (qml) { // We can't check the availability of test functions until @@ -1295,9 +1295,9 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) QTest::qt_snprintf(buf + off, qMin(512 - off, 3), "()"); // append "()" int idx = QTest::currentTestObject->metaObject()->indexOfMethod(buf); if (idx < 0 || !isValidSlot(QTest::currentTestObject->metaObject()->method(idx))) { - printf("Unknown testfunction: '%s'\n", buf); - printf("Available testfunctions:\n"); - qPrintTestSlots(); + fprintf(stderr, "Unknown testfunction: '%s'\n", buf); + fprintf(stderr, "Available testfunctions:\n"); + qPrintTestSlots(stderr); exit(1); } testFuncs[testFuncCount].set(idx, data); @@ -1307,7 +1307,7 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) } if (QTest::seedSet && !QTest::randomOrder) { - printf("-seed requires -random\n"); + fprintf(stderr, "-seed requires -random\n"); exit(1); } } @@ -1466,8 +1466,8 @@ static bool qInvokeTestMethod(const char *slotName, const char *data=0) if (!*data) data = 0; else { - printf("Unknown testdata for function %s: '%s'\n", slotName, data); - printf("Function has no testdata.\n"); + fprintf(stderr, "Unknown testdata for function %s: '%s'\n", slotName, data); + fprintf(stderr, "Function has no testdata.\n"); return false; } } @@ -1492,10 +1492,10 @@ static bool qInvokeTestMethod(const char *slotName, const char *data=0) } if (data && !foundFunction) { - printf("Unknown testdata for function %s: '%s'\n", slotName, data); - printf("Available testdata:\n"); + fprintf(stderr, "Unknown testdata for function %s: '%s'\n", slotName, data); + fprintf(stderr, "Available testdata:\n"); for(int i = 0; i < table.dataCount(); ++i) - printf("%s\n", table.testData(i)->dataTag()); + fprintf(stderr, "%s\n", table.testData(i)->dataTag()); return false; } -- cgit v1.2.3