Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show output only for failing tests #559

Merged
merged 4 commits into from
Nov 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion JGE/include/DebugRoutines.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// dirty, but I get OS header includes this way
#include "JGE.h"

#include "OutputCapturer.h"

#include <ostream>
#include <iostream>
#include <iomanip>
Expand All @@ -29,12 +31,23 @@ std::string ToHex(T* pointer)
#if defined (WIN32) || defined (LINUX)

#ifdef QT_CONFIG

#ifdef CAPTURE_STDERR
#define DebugTrace(inString) \
{ \
std::ostringstream stream; \
stream << inString; \
OutputCapturer::add(stream.str()); \
}
#else // CAPTURE_STDERR
#define DebugTrace(inString) \
{ \
std::ostringstream stream; \
stream << inString; \
qDebug("%s", stream.str().c_str()); \
qDebug("%s", stream.str().c_str()); \
}
#endif // CAPTURE_STDERR

#elif defined (ANDROID)
#include <android/log.h>
#define DebugTrace(inString) \
Expand Down
23 changes: 23 additions & 0 deletions JGE/include/OutputCapturer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef OUTPUTCAPTURER_H
#define OUTPUTCAPTURER_H

#if defined(QT_CONFIG)
#include <Qt>
#include <string>
#include <sstream>
#include "Threading.h"

class OutputCapturer
{
private:
static std::ostringstream stream;
static boost::mutex mMutex;

public:
static void add(const std::string& s);
static void debugAndClear();
static void clear();
};
#endif

#endif // OUTPUTCAPTURER_H
1 change: 0 additions & 1 deletion JGE/include/Threading.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ namespace boost
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>

#include "../include/DebugRoutines.h"
#include "../include/JLogger.h"

namespace boost
Expand Down
22 changes: 22 additions & 0 deletions JGE/src/OutputCapturer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "../include/OutputCapturer.h"

std::ostringstream OutputCapturer::stream;
boost::mutex OutputCapturer::mMutex;

void OutputCapturer::add(const std::string& s)
{
boost::mutex::scoped_lock lock(mMutex);
stream << s << "\n";
}

void OutputCapturer::debugAndClear()
{
stream.flush();
qDebug("%s", stream.str().c_str());
stream.str("");
}

void OutputCapturer::clear()
{
stream.str("");
}
6 changes: 5 additions & 1 deletion JGE/src/Qtconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ int main(int argc, char* argv[])
options.reloadProfile();
TestSuite testSuite("test/_tests.txt");
result = testSuite.run();
int totalTests = testSuite.nbTests + testSuite.nbAITests;
delete wagicCore;
DebugTrace("TestSuite done: failed test: " << result);
DebugTrace("TestSuite done: failed test: " << result << " out of " << totalTests << " total");
#ifdef CAPTURE_STDERR
OutputCapturer::debugAndClear();
#endif
return result;
}
12 changes: 12 additions & 0 deletions projects/mtg/src/TestSuiteAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,15 @@ void TestSuiteGame::assertGame()
Log("<span class=\"success\">==Test Succesful !==</span>");
else
Log("<span class=\"error\">==Test Failed !==</span>");
#ifdef CAPTURE_STDERR
if (error)
{
OutputCapturer::debugAndClear();
} else
{
OutputCapturer::clear();
}
#endif
mMutex.unlock();
}

Expand Down Expand Up @@ -585,6 +594,9 @@ void TestSuite::ThreadProc(void* inParam)
{
LOG("Entering TestSuite::ThreadProc");
TestSuite* instance = reinterpret_cast<TestSuite*>(inParam);
#ifdef CAPTURE_STDERR
OutputCapturer::debugAndClear();
#endif
if (instance)
{
string filename;
Expand Down
2 changes: 2 additions & 0 deletions projects/mtg/wagic-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ SOURCES += \
../../JGE/src/pc/JSocket.cpp\
../../JGE/src/pc/JSfx.cpp\
../../JGE/src/JSprite.cpp\
../../JGE/src/OutputCapturer.cpp\
../../JGE/src/Vector2D.cpp\
../../JGE/src/tinyxml/tinystr.cpp\
../../JGE/src/tinyxml/tinyxml.cpp\
Expand Down Expand Up @@ -393,6 +394,7 @@ HEADERS += \
../../JGE/include/JSpline.h\
../../JGE/include/JSprite.h\
../../JGE/include/JTypes.h\
../../JGE/include/OutputCapturer.h\
../../JGE/include/Vector2D.h\
../../JGE/include/Vector3D.h\
../../JGE/include/vram.h\
Expand Down
2 changes: 1 addition & 1 deletion travis-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ make -j 8

# let's try an Intel linux binary
cd ../..
qmake projects/mtg/wagic-qt.pro CONFIG+=console CONFIG+=debug
qmake projects/mtg/wagic-qt.pro CONFIG+=console CONFIG+=debug DEFINES+=CAPTURE_STDERR
make -j 8

# and finish by running the testsuite
Expand Down