It became apparent that in order to assure obos tests are run

with obos libs and r5 tests are run with r5 libs, two separate
unit testing programs in different directories would be needed.
Thus UnitTester is now just a shell program that calls the
appropriate unittester/UnitTester or unittester_r5/UnitTester_r5
program.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@703 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder 2002-08-11 03:45:17 +00:00
parent d8575caf51
commit c5ff4aa6f5
5 changed files with 86 additions and 89 deletions

View File

@ -228,7 +228,7 @@ NOTFILE r5tests ;
rule CommonTestLib
{
# CommonUnitTest <target> : <sources> : <obos libraries>
# CommonTestLib <target> : <sources> : <obos libraries>
# : <r5 libraries> : <test libraries> : <public headers>;
# Builds a unit test for both OBOS and R5 modules.
# <target> The name of the target.
@ -243,10 +243,8 @@ rule CommonTestLib
# <public headers> A list of public header dirs (as passed to
# UsePublicHeaders).
local testlibdir = [ FDirName $(OBOS_TEST_DIR) lib ] ; #/boot/home/config/lib/obos_tests ;
TestLib $(1) : $(2) : $(testlibdir) : $(3) $(5) : $(6) ;
R5TestLib $(1) : $(2) : $(testlibdir) : $(4) [ R5SharedLibraryNames $(5) ] ;
TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester lib ] : $(3) $(5) : $(6) ;
R5TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester_r5 lib ] : $(4) [ R5SharedLibraryNames $(5) ] ;
}
rule TestLib
@ -280,7 +278,7 @@ rule TestLib
rule R5TestLib
{
# R5UnitTest <target> : <sources> : <dest> : <libraries>
# R5TestLib <target> : <sources> : <dest> : <libraries>
# Builds a unit test for an R5 module. "_r5" is appended to the object
# and the target name.
# <target> The name of the target.
@ -290,7 +288,7 @@ rule R5TestLib
local target = $(1:B)_r5$(1:S) ;
local sources = $(2) ;
local dest = $(3)_r5 ;
local dest = $(3) ;
local libraries = $(4) ;
local objects = [ R5ObjectNames $(sources) ] ;

View File

@ -8,11 +8,26 @@ CommonTestLib libexampletest.so
:
;
UnitTest UnitTester
UnitTest UnitTester
: UnitTester.cpp
:
:
: be stdc++.r4
:
;
UnitTest UnitTesterHelper
: UnitTesterHelper.cpp
: unittester
: be stdc++.r4
: be stdc++.r4
:
;
R5UnitTest UnitTesterHelper
: UnitTesterHelper.cpp
: unittester_r5
: be stdc++.r4
: be stdc++.r4
# : be stdc++.r4
:
;

View File

@ -1,79 +1,46 @@
#include "UnitTester.h"
#include <SemaphoreSyncObject.h>
#include <Directory.h>
#include <string>
#include <iostream>
#include <unistd.h>
// ##### Include headers for statically linked tests here #####
//#include <ExampleTest.h>
UnitTesterShell shell("OpenBeOS Unit Testing Framework", new SemaphoreSyncObject);
int main(int argc, char *argv[]) {
// ##### Add test suites for statically linked tests here #####
// shell.AddTest( "Example", ExampleTest::Suite() );
BTestShell::SetGlobalShell(&shell);
// Load our dynamically linked tests
return shell.Run(argc, argv);
}
//const std::string UnitTesterShell::defaultLibDir = "./lib";
UnitTesterShell::UnitTesterShell(const std::string &description, SyncObject *syncObject)
: BTestShell(description, syncObject)
, doR5Tests(false)
{
}
void
UnitTesterShell::PrintDescription(int argc, char *argv[]) {
std::string AppName = argv[0];
cout << endl;
cout << "This program is the central testing framework for the purpose" << endl;
cout << "of testing and verifying the various kits, classes, functions," << endl;
cout << "and the like that comprise OpenBeOS." << endl;
/*
if (AppName.rfind("UnitTester_r5") != std::string::npos) {
cout << endl;
cout << "Judging by its name (UnitTester_r5), this copy was" << endl;
cout << "probably linked against Be Inc.'s R5 implementations" << endl;
cout << "for the sake of comparison." << endl;
} else if (AppName.rfind("UnitTester") != std::string::npos) {
cout << endl;
cout << "Judging by its name (UnitTester), this copy was probably" << endl;
cout << "linked against our own OpenBeOS implementations." << endl;
}
/* Since some of our obos libraries (such as libtranslation.so) have
identically named R5 equivalents, it was necessary to have two
separate unit testing programs, each with their own lib/ subdir,
to make sure that the obos tests are run with obos libs while
the r5 tests are run with r5 libs.
In the interest of keeping things simple (and not invalidating
the instructions sitting in the newsletter article I wrote :-),
this shell program has been created to allow all unit tests to
still be run from a single application. All it does is filter
out "-obos" and "-r5" arguments and run the appropriate
UnitTesterHelper program (which does all the hard work).
*/
int main(int argc, char *argv[]) {
// Look for "-obos" or "-r5" arguments, then run
// the appropriate UnitTesterHelper program, letting
// it do all the dirty work.
bool doR5Tests = false;
bool beVerbose = false;
std::string cmd = "";
for (int i = 1; i < argc; i++) {
std::string arg(argv[i]);
if (arg == "-r5")
doR5Tests = true;
else if (arg == "-obos")
doR5Tests = false;
else {
if (arg.length() == 3 && arg[0] == '-' && arg[1] == 'v'
&& '0' <= arg[2] && arg[2] <= '9')
{
beVerbose = (arg[2] - '0') >= 4;
}
cmd += " " + arg;
}
}
cmd = (doR5Tests ? "unittester_r5/UnitTesterHelper_r5" : "unittester/UnitTesterHelper") + cmd;
if (beVerbose)
cout << "Executing: '" << cmd << "'" << endl;
system(cmd.c_str());
return 0;
}
void
UnitTesterShell::PrintValidArguments() {
BTestShell::PrintValidArguments();
cout << indent << "-obos Runs tests linked against our OpenBeOS libraries (*default*)" << endl;
cout << indent << "-r5 Runs tests linked against Be Inc.'s R5 libraries (instead" << endl;
cout << indent << " of our libraries) for the sake of comparison." << endl;
}
bool
UnitTesterShell::ProcessArgument(std::string arg, int argc, char *argv[]) {
if (arg == "-r5") {
doR5Tests = true;
} else if (arg == "-obos") {
doR5Tests = false;
} else
return BTestShell::ProcessArgument(arg, argc, argv);
return true;
}
void
UnitTesterShell::LoadDynamicSuites() {
// Add the appropriate test lib path
string defaultLibDir = string(GlobalTestDir()) + "/lib";
fLibDirs.insert(defaultLibDir + (doR5Tests ? "_r5" : ""));
// Load away
BTestShell::LoadDynamicSuites();
}

View File

@ -26,7 +26,7 @@ CommonTestLib libstoragetest.so
# To run the tests the libraries must be around.
{
local libdir = [ on UnitTester FDirName $(LOCATE[1]) lib ] ;
local libdir = [ on UnitTesterHelper FDirName $(LOCATE[1]) lib ] ;
MakeLocate <$(SOURCE_GRIST)>libstorage.so : $(libdir) ;
MakeLocate <$(SOURCE_GRIST)>libbeadapter.so : $(libdir) ;
RelSymLink <$(SOURCE_GRIST)>libstorage.so : libstorage.so ;
@ -38,7 +38,7 @@ CommonTestLib libstoragetest.so
# To run the tests some test files must be around.
{
local resdir = <storage!kit!test!files>resources ;
MakeLocate $(resdir) : [ on UnitTester return $(LOCATE[1]) ] ;
MakeLocate $(resdir) : [ on UnitTesterHelper return $(LOCATE[1]) ] ;
RelSymLink $(resdir) : [ FDirName $(SUBDIR) resources ] ;
DEPENDS libstoragetest.so : $(resdir) ;
}

View File

@ -148,7 +148,11 @@ BTestShell::Run(int argc, char *argv[]) {
for (i = fTestsToRun.begin(); i != fTestsToRun.end(); ++i) {
// See if it's a suite (since it may just be a single test)
if (fSuites.find(*i) != fSuites.end()) {
suitesToRemove.insert(*i); // Note the suite name for later
// Note the suite name for later removal unless the
// name is also the name of an available individual test
if (fTests.find(*i) == fTests.end()) {
suitesToRemove.insert(*i);
}
const TestMap &tests = fSuites[*i]->getTests();
TestMap::const_iterator j;
for (j = tests.begin(); j != tests.end(); j++) {
@ -158,7 +162,8 @@ BTestShell::Run(int argc, char *argv[]) {
}
// Remove the names of all of the suites we discovered from the
// list of tests to run
// list of tests to run (unless there's also an installed individual
// test of the same name).
for (i = suitesToRemove.begin(); i != suitesToRemove.end(); i++) {
fTestsToRun.erase(*i);
}
@ -382,6 +387,18 @@ BTestShell::LoadDynamicSuites() {
if (Verbosity() >= v3)
cout << endl;
// Look for suites and tests with the same name and give a
// warning, as this is only asking for trouble... :-)
for (SuiteMap::const_iterator i = fSuites.begin(); i != fSuites.end(); i++) {
if (fTests.find(i->first) != fTests.end() && Verbosity() > v0) {
cout << "WARNING: '" << i->first << "' refers to both a test suite *and* an individual" <<
endl << " test. Both will be executed, but it is reccommended you rename" <<
endl << " one of them to resolve the conflict." <<
endl << endl;
}
}
}
void