Unit testing update:
- Verbosity is now honored globally - Added BTestCase::Outputf() - Migrated BNode, BStatable, BDirectory, and BPath tests - Added CommonTestLib, TestLib, and R5TestLib rules to Jamrules - Updated Jamfiles for unit testing stuff - Probably a few other things I've forgotten git-svn-id: file:///srv/svn/repos/haiku/trunk/current@269 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -16,6 +16,11 @@ public:
|
||||
//! Starts a new sub test block (i.e. prints a newline :-)
|
||||
virtual void NextSubTestBlock();
|
||||
|
||||
/*! \brief Prints to standard out just like printf, except shell verbosity
|
||||
settings are honored.
|
||||
*/
|
||||
virtual void Outputf(const char *str, ...);
|
||||
|
||||
//! Saves the location of the current working directory.
|
||||
void SaveCWD();
|
||||
|
||||
@@ -24,6 +29,9 @@ public:
|
||||
//! Restores the current working directory to last directory saved by a call to SaveCWD().
|
||||
void RestoreCWD(const char *alternate = NULL);
|
||||
protected:
|
||||
//! Returns true if the current shell settings allow us to print to standard output.
|
||||
bool BeVerbose();
|
||||
|
||||
bool fValidCWD;
|
||||
char fCurrentWorkingDir[B_PATH_NAME_LENGTH+1];
|
||||
int32 fSubTestNum;
|
||||
|
||||
@@ -64,41 +64,69 @@ public:
|
||||
// Returns true if verbosity is high enough that individual tests are
|
||||
// allowed to make noise.
|
||||
bool BeVerbose() const { return Verbosity() >= v2; };
|
||||
|
||||
|
||||
static bool GlobalBeVerbose() { return (fGlobalShell ? fGlobalShell->BeVerbose() : true); };
|
||||
|
||||
// Returns a pointer to a global BTestShell object. This function is
|
||||
// something of a hack, used to give BTestCase and its subclasses
|
||||
// access to verbosity information. Don't rely on it if you don't
|
||||
// have to (and always make sure the pointer it returns isn't NULL
|
||||
// before you try to use it :-).
|
||||
static BTestShell* Shell() { return fGlobalShell; };
|
||||
static void SetShell(BTestShell *shell) { fGlobalShell = shell; };
|
||||
|
||||
// Sets the global BTestShell pointer. The BTestShell class does
|
||||
// not assume ownership of the object.
|
||||
static void SetShell(BTestShell *shell) { fGlobalShell = shell; };
|
||||
|
||||
protected:
|
||||
VerbosityLevel fVerbosityLevel;
|
||||
std::set<std::string> fTestsToRun;
|
||||
std::map<std::string, CppUnit::Test*> fTests;
|
||||
std::map<std::string, BTestSuite*> fSuites;
|
||||
std::map<std::string, BTestSuite*> fSuites;
|
||||
std::set<std::string> fLibDirs;
|
||||
CppUnit::TestResult fTestResults;
|
||||
CppUnit::TestResultCollector fResultsCollector;
|
||||
std::string fDescription;
|
||||
static BTestShell* fGlobalShell;
|
||||
static const char indent[];
|
||||
bool fListTestsAndExit;
|
||||
|
||||
// Prints a brief description of the program and a guess as to
|
||||
// which Storage Kit library the app was linked with based on
|
||||
// the filename of the app
|
||||
//! Prints a brief description of the program.
|
||||
virtual void PrintDescription(int argc, char *argv[]);
|
||||
|
||||
// Prints out command line argument instructions
|
||||
//! Prints out command line argument instructions
|
||||
void PrintHelp();
|
||||
|
||||
/*! \brief Prints out the list of valid command line arguments.
|
||||
Called by PrintHelp().
|
||||
*/
|
||||
virtual void PrintValidArguments();
|
||||
|
||||
// Handles command line arguments; returns true if everything goes
|
||||
// okay, false if not (or if the program just needs to terminate without
|
||||
// running any tests). Modifies settings in "settings" as necessary.
|
||||
//! Prints out a list of all the currently available tests
|
||||
void PrintInstalledTests();
|
||||
|
||||
/*! \brief Handles command line arguments; returns true if everything goes
|
||||
okay, false if not (or if the program just needs to terminate without
|
||||
running any tests). Modifies settings in "settings" as necessary.
|
||||
*/
|
||||
bool ProcessArguments(int argc, char *argv[]);
|
||||
|
||||
//! Processes a single argument, given by the \c arg parameter.
|
||||
virtual bool ProcessArgument(std::string arg, int argc, char *argv[]);
|
||||
|
||||
// Makes any necessary pre-test preparations
|
||||
//! Makes any necessary pre-test preparations
|
||||
void InitOutput();
|
||||
|
||||
// Prints out the test results in the proper format per
|
||||
// the specified verbosity level.
|
||||
/*! \brief Prints out the test results in the proper format per
|
||||
the specified verbosity level.
|
||||
*/
|
||||
void PrintResults();
|
||||
|
||||
/*! \brief Searches all the paths in \c fLibDirs, loading any dynamically
|
||||
loadable suites it finds.
|
||||
*/
|
||||
virtual void LoadDynamicSuites();
|
||||
|
||||
private:
|
||||
//! Prevents the use of the copy constructor.
|
||||
BTestShell( const BTestShell © );
|
||||
|
||||
@@ -10,7 +10,7 @@ class CppUnit::TestResult;
|
||||
//! Groups together a set of tests for a given kit.
|
||||
class BTestSuite : public CppUnit::Test {
|
||||
public:
|
||||
BTestSuite( std::string name );
|
||||
BTestSuite( std::string name = "" );
|
||||
virtual ~BTestSuite();
|
||||
|
||||
virtual void run( CppUnit::TestResult *result );
|
||||
|
||||
@@ -153,6 +153,7 @@ BThreadedTestCaller<TestClass, ExpectedException>::run(CppUnit::TestResult *resu
|
||||
// Try to acquire the semaphore
|
||||
err = acquire_sem_etc(fThreadSem, fThreads.size(), B_RELATIVE_TIMEOUT, 500000);
|
||||
|
||||
// Get a pointer to the current global shell
|
||||
BTestShell *shell = BTestShell::Shell();
|
||||
|
||||
// Empty the UpdateList
|
||||
@@ -161,7 +162,9 @@ BThreadedTestCaller<TestClass, ExpectedException>::run(CppUnit::TestResult *resu
|
||||
i != list.end();
|
||||
i++)
|
||||
{
|
||||
if (shell && shell->BeVerbose()) {
|
||||
// Only print to standard out if the current global shell
|
||||
// lets us (or if no global shell is designated).
|
||||
if ((shell && shell->BeVerbose()) || !shell) {
|
||||
printf("%s", (*i).c_str());
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,16 @@ public:
|
||||
thread in which it's called (i.e. [A.0][B.0][A.1][A.2][B.1]...). */
|
||||
virtual void NextSubTest();
|
||||
|
||||
/*! \brief Prints to standard out just like printf, except shell verbosity
|
||||
settings are honored, and output from threads other than the main thread
|
||||
happens before the test is over.
|
||||
|
||||
\note Currently your output is limited to a length of 1024 characters. If
|
||||
you really need to print a single string that's long than that, fix the
|
||||
function yourself :-).
|
||||
*/
|
||||
virtual void Outputf(const char *str, ...);
|
||||
|
||||
//! Saves the location of the current working directory.
|
||||
void SaveCWD();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user