-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
unit tests #4259
unit tests #4259
Changes from all commits
04e5a84
af97db6
c71945c
8028d57
afc7c06
2291da7
4d8e1e6
e9a0476
c63608e
660e9c4
bf1848b
00354b6
9470528
7037284
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* ofxUnitTestsApp.h | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this header doesn't match the filename? |
||
* | ||
* Created on: Jul 8, 2015 | ||
* Author: arturo | ||
*/ | ||
#pragma once | ||
|
||
#include "ofConstants.h" | ||
#include "ofLog.h" | ||
#include "ofBaseApp.h" | ||
#include "ofAppRunner.h" | ||
#include <string> | ||
|
||
class ofColorsLoggerChannel: public ofBaseLoggerChannel{ | ||
std::string CON_DEFAULT="\033[0m"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do these flags work on non-unixes? if not, might be a good idea to formulate this in a cross-platform way. |
||
std::string CON_BOLD="\033[1m"; | ||
std::string CON_RED="\033[31m"; | ||
std::string CON_YELLOW="\033[33m"; | ||
std::string CON_GREEN="\033[32m"; | ||
std::string getColor(ofLogLevel level) const{ | ||
switch(level){ | ||
case OF_LOG_FATAL_ERROR: | ||
case OF_LOG_ERROR: | ||
return CON_RED; | ||
case OF_LOG_WARNING: | ||
return CON_YELLOW; | ||
case OF_LOG_NOTICE: | ||
return CON_GREEN; | ||
default: | ||
return CON_DEFAULT; | ||
} | ||
} | ||
public: | ||
void log(ofLogLevel level, const std::string & module, const std::string & message){ | ||
// print to cerr for OF_LOG_ERROR and OF_LOG_FATAL_ERROR, everything else to cout | ||
std::cout << "[" << ofGetLogLevelName(level, true) << "] "; | ||
// only print the module name if it's not "" | ||
if(module != ""){ | ||
std::cout << module << ": "; | ||
} | ||
std::cout << CON_BOLD << getColor(level) << message << CON_DEFAULT << std::endl; | ||
} | ||
|
||
void log(ofLogLevel level, const std::string & module, const char* format, ...){ | ||
va_list args; | ||
va_start(args, format); | ||
log(level, module, format, args); | ||
va_end(args); | ||
} | ||
|
||
void log(ofLogLevel level, const std::string & module, const char* format, va_list args){ | ||
//thanks stefan! | ||
//http://www.ozzu.com/cpp-tutorials/tutorial-writing-custom-printf-wrapper-function-t89166.html | ||
fprintf(stdout, (CON_BOLD + getColor(level) + "[%s] " + CON_DEFAULT).c_str(), ofGetLogLevelName(level, true).c_str()); | ||
if(module != ""){ | ||
fprintf(stdout, "%s: ", module.c_str()); | ||
} | ||
vfprintf(stdout, format, args); | ||
fprintf(stdout, "\n"); | ||
} | ||
}; | ||
|
||
class ofxUnitTestsApp: public ofBaseApp{ | ||
void setup(){ | ||
ofSetLoggerChannel(std::shared_ptr<ofBaseLoggerChannel>(new ofColorsLoggerChannel)); | ||
run(); | ||
|
||
if(numTestsFailed == 0){ | ||
ofLogNotice() << numTestsPassed << "/" << numTestsTotal << " tests passed"; | ||
}else{ | ||
ofLogError() << numTestsFailed << "/" << numTestsTotal << " tests failed"; | ||
} | ||
ofExit(numTestsFailed); | ||
} | ||
virtual void run() = 0; | ||
|
||
protected: | ||
void test(bool test, const std::string & testName, const std::string & msg, const std::string & file, int line){ | ||
numTestsTotal++; | ||
if(test){ | ||
ofLogNotice() << testName << " passed"; | ||
numTestsPassed++; | ||
}else{ | ||
ofLogError() << testName << " failed " << msg; | ||
ofLogError() << file << ": " << line; | ||
numTestsFailed++; | ||
} | ||
} | ||
|
||
void test(bool test, const std::string & testName, const std::string & file, int line){ | ||
this->test(test,testName,"",file,line); | ||
} | ||
|
||
template<typename T1, typename T2> | ||
void test_eq(T1 t1, T2 t2, const std::string & testName, const std::string & msg, const std::string & file, int line){ | ||
numTestsTotal++; | ||
if(t1==t2){ | ||
ofLogNotice() << testName << " passed"; | ||
numTestsPassed++; | ||
}else{ | ||
ofLogError() << testName << " failed " << msg; | ||
ofLogError() << "value1 " << t1; | ||
ofLogError() << "value2 " << t2; | ||
ofLogError() << file << ": " << line; | ||
numTestsFailed++; | ||
} | ||
} | ||
|
||
template<typename T1, typename T2> | ||
void test_eq(T1 t1, T2 t2, const std::string & testName, const std::string & file, int line){ | ||
test_eq(t1,t2,testName,"",file,line); | ||
} | ||
|
||
private: | ||
int numTestsTotal = 0; | ||
int numTestsPassed = 0; | ||
int numTestsFailed = 0; | ||
}; | ||
|
||
#define test(x, ...) this->test(x,__VA_ARGS__,__FILE__,__LINE__) | ||
#define test_eq(x, ...) this->test_eq(x,__VA_ARGS__,__FILE__,__LINE__) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,11 +13,18 @@ echo "PLATFORM_CFLAGS += $CUSTOMFLAGS" >> libs/openFrameworksCompiled/project/li | |
cd libs/openFrameworksCompiled/project | ||
make Debug | ||
|
||
echo "Building emptyExample" | ||
cd $ROOT | ||
cp scripts/linux/template/linux64/Makefile examples/empty/emptyExample/ | ||
cp scripts/linux/template/linux64/config.make examples/empty/emptyExample/ | ||
cd examples/empty/emptyExample | ||
# this is not even necessary if we include that in the default.mk above | ||
# echo "PROJECT_CFLAGS = $CUSTOMFLAGS" >> config.make | ||
make Debug | ||
echo "Unit tests" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @arturoc why did you delete this part? I don't think a CI build is really sensible if we can't even build the emptyexample. Even if we don't want to build that temporarily, why delete this and not simply comment it out and adding some explanation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. building empty example makes the build crash and my suspicion is that this is happening because empty example is including ofMain.h which is huge. i've changed it to build the tests which are much lighter because they only include the headers that are needed and it seems to work better. the tests are also normal applications so if those are building emptyExample should build too. empty example is also building in osx so we will catch most possible errors affecting emptyExample but not the tests there There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
unit tests also make the build crash, so you just replaced one build-crashing application with another... |
||
cd $ROOT/tests | ||
for group in *; do | ||
if [ -d $group ]; then | ||
for test in $group/*; do | ||
if [ -d $test ]; then | ||
cd $test | ||
cp ../../../scripts/linux/template/linux/Makefile . | ||
cp ../../../scripts/linux/template/linux/config.make . | ||
make Debug | ||
make RunDebug | ||
fi | ||
done | ||
fi | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,19 @@ set -ev | |
echo "Building openFrameworks - OSX Template Project" | ||
ROOT=${TRAVIS_BUILD_DIR:-"$( cd "$(dirname "$0")/../../.." ; pwd -P )"} | ||
xcodebuild -configuration Release -target emptyExample -project "$ROOT/scripts/osx/template/emptyExample.xcodeproj" | ||
|
||
echo "Unit tests" | ||
cd $ROOT/tests | ||
for group in *; do | ||
if [ -d $group ]; then | ||
for test in $group/*; do | ||
if [ -d $test ]; then | ||
cd $test | ||
cp ../../../scripts/osx/template/Makefile . | ||
cp ../../../scripts/osx/template/config.make . | ||
make Debug | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @arturoc wouldn't it be better to also use xcodebuild for this (or make for the main compilation) to have homogenity in the build system per platform? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw, this compiles OF library twice, once with xcode, and once with make, see https://travis-ci.org/openframeworks/openFrameworks/jobs/75829657#L984 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i know, i'll change it when i have time but if i use xcodebuild i need to compile the PG, generate the project for the tests and then compile them so it's not trivial. i'll probably move the PG generation here if i finally do it like that |
||
make RunDebug | ||
fi | ||
done | ||
fi | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
######################### | ||
# core examples | ||
######################### | ||
|
||
*/*/bin/* | ||
!*/*/bin/data/ | ||
|
||
######################### | ||
# IDE | ||
######################### | ||
|
||
# XCode | ||
/*/*/*.xcodeproj | ||
/*/*/Project.xcconfig | ||
/*/*/openFrameworks-Info.plist | ||
/*/*/ofxiOS-Info.plist | ||
/*/*/ofxiOS_Prefix.pch | ||
/*/*/*/*/Default*.png | ||
/*/*/*/*/Icon*.png | ||
|
||
# Code::Blocks | ||
/*/*/*.cbp | ||
/*/*/*.workspace | ||
|
||
# Visual Studio | ||
/*/*/*.sln | ||
/*/*/*.vcxproj | ||
/*/*/*.vcxproj.user | ||
/*/*/*.vcxproj.filters | ||
/*/*/icon.rc | ||
|
||
# Eclipse | ||
/*/*/.cproject | ||
/*/*/.project | ||
/*/*/.settings/ | ||
|
||
######################### | ||
# operating system | ||
######################### | ||
|
||
# Linux | ||
/*/*/Makefile | ||
/*/*/config.make | ||
# Leave Android files in until project generation works | ||
!/android/*/Makefile | ||
!/android/*/config.make | ||
|
||
# Android | ||
android/*/test link | ||
android/*/gen | ||
android/*/res/raw | ||
libOFAndroidApp*.so | ||
gdbserver | ||
gdb.setup | ||
libneondetection.so | ||
Application.mk | ||
Android.mk | ||
|
||
!/android/*/.cproject | ||
!/android/*/.project | ||
!/android/*/.settings |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ofxUnitTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturoc I very much would prefer if we left the linux build in allow_failures, so that we can still get a feeling how often the build fails due to memory concerns, and if whatever measures we implement have a meaningful impact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, this stil has some builds failing because of memory issues: https://travis-ci.org/openframeworks/openFrameworks/jobs/75839351#L1494