From afc6d4507dbfc63b4bdc97065320921a4801d778 Mon Sep 17 00:00:00 2001 From: Pete Johns Date: Sun, 26 Sep 2010 16:52:30 +1000 Subject: [PATCH] Removed static std::string. which_test() doesn't have to calculate anything, could be inlined. --- test/options.cpp | 12 ++++++------ test/options.h | 1 + test/testoptions.cpp | 9 +++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/test/options.cpp b/test/options.cpp index bbadf71f7..63db454c4 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -20,9 +20,14 @@ options::options(int argc, const char* argv[]) :_options(&argv[1], &argv[0] + argc) ,_gcc_style_errors(_options.count("-g") != 0) ,_quiet(_options.count("-q") != 0) + ,_which_test("") { _options.erase("-g"); _options.erase("-q"); + if (not _options.empty()) + { + _which_test = *_options.rbegin(); + } } bool options::quiet() const @@ -37,11 +42,6 @@ bool options::gcc_style_errors() const const std::string& options::which_test() const { - static std::string ret = ""; - if (not _options.empty()) - { - ret = *_options.rbegin(); - } - return ret; + return _which_test; } diff --git a/test/options.h b/test/options.h index 9cb6c73d5..6475507f0 100644 --- a/test/options.h +++ b/test/options.h @@ -37,6 +37,7 @@ private: std::set _options; const bool _gcc_style_errors; const bool _quiet; + std::string _which_test; }; #endif diff --git a/test/testoptions.cpp b/test/testoptions.cpp index 4e654e52c..9d8f18d40 100644 --- a/test/testoptions.cpp +++ b/test/testoptions.cpp @@ -34,6 +34,7 @@ private: { TEST_CASE(which_test); TEST_CASE(which_test_method); + TEST_CASE(no_test_method); TEST_CASE(not_quiet); TEST_CASE(quiet); TEST_CASE(gcc_errors); @@ -58,6 +59,14 @@ private: } + void no_test_method() + { + const char* argv[] = {"./test_runner"}; + options args(sizeof argv / sizeof argv[0], argv); + ASSERT_EQUALS("", args.which_test()); + } + + void not_quiet() { const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-v"};