Lots of changes:
* changes the XML report format to match JUnit/Ant's. * improves file path handling. * allows the user to disable RTTI using the GTEST_HAS_RTTI macro. * makes the code compile with -Wswitch-enum.
This commit is contained in:
@@ -55,6 +55,7 @@ class TestPartResult {
|
||||
: type_(type),
|
||||
file_name_(file_name),
|
||||
line_number_(line_number),
|
||||
summary_(ExtractSummary(message)),
|
||||
message_(message) {
|
||||
}
|
||||
|
||||
@@ -69,6 +70,9 @@ class TestPartResult {
|
||||
// or -1 if it's unknown.
|
||||
int line_number() const { return line_number_; }
|
||||
|
||||
// Gets the summary of the failure message.
|
||||
const char* summary() const { return summary_.c_str(); }
|
||||
|
||||
// Gets the message associated with the test part.
|
||||
const char* message() const { return message_.c_str(); }
|
||||
|
||||
@@ -86,12 +90,17 @@ class TestPartResult {
|
||||
private:
|
||||
TestPartResultType type_;
|
||||
|
||||
// Gets the summary of the failure message by omitting the stack
|
||||
// trace in it.
|
||||
static internal::String ExtractSummary(const char* message);
|
||||
|
||||
// The name of the source file where the test part took place, or
|
||||
// NULL if the source file is unknown.
|
||||
internal::String file_name_;
|
||||
// The line in the source file where the test part took place, or -1
|
||||
// if the line number is unknown.
|
||||
int line_number_;
|
||||
internal::String summary_; // The test failure summary.
|
||||
internal::String message_; // The test failure message.
|
||||
};
|
||||
|
||||
|
||||
@@ -60,8 +60,19 @@ class FilePath {
|
||||
public:
|
||||
FilePath() : pathname_("") { }
|
||||
FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { }
|
||||
explicit FilePath(const char* pathname) : pathname_(pathname) { }
|
||||
explicit FilePath(const String& pathname) : pathname_(pathname) { }
|
||||
|
||||
explicit FilePath(const char* pathname) : pathname_(pathname) {
|
||||
Normalize();
|
||||
}
|
||||
|
||||
explicit FilePath(const String& pathname) : pathname_(pathname) {
|
||||
Normalize();
|
||||
}
|
||||
|
||||
FilePath& operator=(const FilePath& rhs) {
|
||||
Set(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Set(const FilePath& rhs) {
|
||||
pathname_ = rhs.pathname_;
|
||||
@@ -149,11 +160,30 @@ class FilePath {
|
||||
// This does NOT check that a directory (or file) actually exists.
|
||||
bool IsDirectory() const;
|
||||
|
||||
private:
|
||||
String pathname_;
|
||||
// Returns true if pathname describes a root directory. (Windows has one
|
||||
// root directory per disk drive.)
|
||||
bool IsRootDirectory() const;
|
||||
|
||||
// Don't implement operator= because it is banned by the style guide.
|
||||
FilePath& operator=(const FilePath& rhs);
|
||||
private:
|
||||
// Replaces multiple consecutive separators with a single separator.
|
||||
// For example, "bar///foo" becomes "bar/foo". Does not eliminate other
|
||||
// redundancies that might be in a pathname involving "." or "..".
|
||||
//
|
||||
// A pathname with multiple consecutive separators may occur either through
|
||||
// user error or as a result of some scripts or APIs that generate a pathname
|
||||
// with a trailing separator. On other platforms the same API or script
|
||||
// may NOT generate a pathname with a trailing "/". Then elsewhere that
|
||||
// pathname may have another "/" and pathname components added to it,
|
||||
// without checking for the separator already being there.
|
||||
// The script language and operating system may allow paths like "foo//bar"
|
||||
// but some of the functions in FilePath will not handle that correctly. In
|
||||
// particular, RemoveTrailingPathSeparator() only removes one separator, and
|
||||
// it is called in CreateDirectoriesRecursively() assuming that it will change
|
||||
// a pathname from directory syntax (trailing separator) to filename syntax.
|
||||
|
||||
void Normalize();
|
||||
|
||||
String pathname_;
|
||||
}; // class FilePath
|
||||
|
||||
} // namespace internal
|
||||
|
||||
@@ -55,6 +55,9 @@
|
||||
// is/isn't available (some systems define
|
||||
// ::wstring, which is different to std::wstring).
|
||||
// Leave it undefined to let Google Test define it.
|
||||
// GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/isn't
|
||||
// enabled. Leave it undefined to let Google
|
||||
// Test define it.
|
||||
|
||||
// This header defines the following utilities:
|
||||
//
|
||||
@@ -135,6 +138,13 @@
|
||||
#define GTEST_FLAG_PREFIX "gtest_"
|
||||
#define GTEST_FLAG_PREFIX_UPPER "GTEST_"
|
||||
|
||||
// Determines the version of gcc that is used to compile this.
|
||||
#ifdef __GNUC__
|
||||
// 40302 means version 4.3.2.
|
||||
#define GTEST_GCC_VER_ \
|
||||
(__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
|
||||
#endif // __GNUC__
|
||||
|
||||
// Determines the platform on which Google Test is compiled.
|
||||
#ifdef __CYGWIN__
|
||||
#define GTEST_OS_CYGWIN
|
||||
@@ -215,6 +225,42 @@
|
||||
#include <strstream> // NOLINT
|
||||
#endif // GTEST_HAS_STD_STRING
|
||||
|
||||
// Determines whether RTTI is available.
|
||||
#ifndef GTEST_HAS_RTTI
|
||||
// The user didn't tell us whether RTTI is enabled, so we need to
|
||||
// figure it out.
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#ifdef _CPPRTTI // MSVC defines this macro iff RTTI is enabled.
|
||||
#define GTEST_HAS_RTTI 1
|
||||
#else
|
||||
#define GTEST_HAS_RTTI 0
|
||||
#endif // _CPPRTTI
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
// Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
|
||||
#if GTEST_GCC_VER_ >= 40302
|
||||
#ifdef __GXX_RTTI
|
||||
#define GTEST_HAS_RTTI 1
|
||||
#else
|
||||
#define GTEST_HAS_RTTI 0
|
||||
#endif // __GXX_RTTI
|
||||
#else
|
||||
// For gcc versions smaller than 4.3.2, we assume RTTI is enabled.
|
||||
#define GTEST_HAS_RTTI 1
|
||||
#endif // GTEST_GCC_VER >= 40302
|
||||
|
||||
#else
|
||||
|
||||
// Unknown compiler - assume RTTI is enabled.
|
||||
#define GTEST_HAS_RTTI 1
|
||||
|
||||
#endif // _MSC_VER
|
||||
|
||||
#endif // GTEST_HAS_RTTI
|
||||
|
||||
// Determines whether to support death tests.
|
||||
#if GTEST_HAS_STD_STRING && defined(GTEST_OS_LINUX)
|
||||
#define GTEST_HAS_DEATH_TEST
|
||||
@@ -284,13 +330,11 @@
|
||||
// following the argument list:
|
||||
//
|
||||
// Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT;
|
||||
#if defined(__GNUC__) \
|
||||
&& (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) \
|
||||
&& !defined(COMPILER_ICC)
|
||||
#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)
|
||||
#define GTEST_MUST_USE_RESULT __attribute__ ((warn_unused_result))
|
||||
#else
|
||||
#define GTEST_MUST_USE_RESULT
|
||||
#endif // (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
|
||||
#endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
|
||||
|
||||
namespace testing {
|
||||
|
||||
|
||||
@@ -71,6 +71,8 @@ struct AssertTypeEq<T, T> {
|
||||
// GetTypeName<T>() returns a human-readable name of type T.
|
||||
template <typename T>
|
||||
String GetTypeName() {
|
||||
#if GTEST_HAS_RTTI
|
||||
|
||||
const char* const name = typeid(T).name();
|
||||
#ifdef __GNUC__
|
||||
int status = 0;
|
||||
@@ -83,6 +85,10 @@ String GetTypeName() {
|
||||
#else
|
||||
return name;
|
||||
#endif // __GNUC__
|
||||
|
||||
#else
|
||||
return "<type>";
|
||||
#endif // GTEST_HAS_RTTI
|
||||
}
|
||||
|
||||
// A unique type used as the default value for the arguments of class
|
||||
|
||||
@@ -71,6 +71,8 @@ struct AssertTypeEq<T, T> {
|
||||
// GetTypeName<T>() returns a human-readable name of type T.
|
||||
template <typename T>
|
||||
String GetTypeName() {
|
||||
#if GTEST_HAS_RTTI
|
||||
|
||||
const char* const name = typeid(T).name();
|
||||
#ifdef __GNUC__
|
||||
int status = 0;
|
||||
@@ -83,6 +85,10 @@ String GetTypeName() {
|
||||
#else
|
||||
return name;
|
||||
#endif // __GNUC__
|
||||
|
||||
#else
|
||||
return "<type>";
|
||||
#endif // GTEST_HAS_RTTI
|
||||
}
|
||||
|
||||
// A unique type used as the default value for the arguments of class
|
||||
|
||||
Reference in New Issue
Block a user