Skip to content

Commit afc6d45

Browse files
committed
Removed static std::string.
which_test() doesn't have to calculate anything, could be inlined.
1 parent 5dc4759 commit afc6d45

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

test/options.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ options::options(int argc, const char* argv[])
2020
:_options(&argv[1], &argv[0] + argc)
2121
,_gcc_style_errors(_options.count("-g") != 0)
2222
,_quiet(_options.count("-q") != 0)
23+
,_which_test("")
2324
{
2425
_options.erase("-g");
2526
_options.erase("-q");
27+
if (not _options.empty())
28+
{
29+
_which_test = *_options.rbegin();
30+
}
2631
}
2732

2833
bool options::quiet() const
@@ -37,11 +42,6 @@ bool options::gcc_style_errors() const
3742

3843
const std::string& options::which_test() const
3944
{
40-
static std::string ret = "";
41-
if (not _options.empty())
42-
{
43-
ret = *_options.rbegin();
44-
}
45-
return ret;
45+
return _which_test;
4646
}
4747

test/options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class options
3737
std::set<std::string> _options;
3838
const bool _gcc_style_errors;
3939
const bool _quiet;
40+
std::string _which_test;
4041
};
4142

4243
#endif

test/testoptions.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class TestOptions: public TestFixture
3434
{
3535
TEST_CASE(which_test);
3636
TEST_CASE(which_test_method);
37+
TEST_CASE(no_test_method);
3738
TEST_CASE(not_quiet);
3839
TEST_CASE(quiet);
3940
TEST_CASE(gcc_errors);
@@ -58,6 +59,14 @@ class TestOptions: public TestFixture
5859
}
5960

6061

62+
void no_test_method()
63+
{
64+
const char* argv[] = {"./test_runner"};
65+
options args(sizeof argv / sizeof argv[0], argv);
66+
ASSERT_EQUALS("", args.which_test());
67+
}
68+
69+
6170
void not_quiet()
6271
{
6372
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-v"};

0 commit comments

Comments
 (0)