Skip to content

Commit 5ed40a6

Browse files
committed
Fix unittests to not fail unittests with new logging prefix behaviour
1 parent 6afa3cc commit 5ed40a6

File tree

3 files changed

+72
-30
lines changed

3 files changed

+72
-30
lines changed

test/common/test_utils.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,20 @@ namespace testing {
8989
inline static constexpr const char *ERROR_MESSAGE = "Base angle (%f) is less than the minimum angle (%f)";
9090
inline static const std::string EXPECTED_ERROR_MESSAGE = "Base angle (3.300000) is less than the minimum angle (5.500000)\n";
9191
}
92-
}
93-
9492

95-
namespace lpp {
96-
namespace rostest{
93+
namespace rostest {
9794
inline static const std::string debug = "\x1B[m[DEBUG] [.]: Test\x1B[m\n";
9895
inline static const std::string info = "\x1B[m[ INFO] [.]: Test\x1B[m\n";
9996
inline static const std::string warning = "\x1B[m[ WARN] [.]: Test\x1B[m\n";
10097
inline static const std::string error = "\x1B[m[ERROR] [.]: Test\x1B[m\n";
10198
inline static const std::string fatal = "\x1B[m[FATAL] [.]: Test\x1B[m\n";
99+
namespace v2 {
100+
inline static const std::string debug = rostest::debug;
101+
inline static const std::string info = "\x1B[m[INFO] [.]: Test\x1B[m\n";
102+
inline static const std::string warning = "\x1B[m[WARN] [.]: Test\x1B[m\n";
103+
inline static const std::string error = rostest::error;
104+
inline static const std::string fatal = rostest::fatal;
105+
}
102106
}
103107

104108

@@ -108,6 +112,13 @@ inline static const std::string info = "\x1B[m[ INFO] [.]: Base angle (.) is les
108112
inline static const std::string warning = "\x1B[m[ WARN] [.]: Base angle (.) is less than the minimum angle (.)\x1B[m\n";
109113
inline static const std::string error = "\x1B[m[ERROR] [.]: Base angle (.) is less than the minimum angle (.)\x1B[m\n";
110114
inline static const std::string fatal = "\x1B[m[FATAL] [.]: Base angle (.) is less than the minimum angle (.)\x1B[m\n";
115+
namespace v2 {
116+
inline static const std::string debug = rosprintf::debug;
117+
inline static const std::string info = "\x1B[m[INFO] [.]: Base angle (.) is less than the minimum angle (.)\x1B[m\n";
118+
inline static const std::string warning = "\x1B[m[WARN] [.]: Base angle (.) is less than the minimum angle (.)\x1B[m\n";
119+
inline static const std::string error = rosprintf::error;
120+
inline static const std::string fatal = rosprintf::fatal;
121+
}
111122
}
112123

113124

@@ -116,6 +127,12 @@ inline static const std::string info = "\x1B[m[ INFO] [.]: LOG_STRING: collected
116127
inline static const std::string warning = "\x1B[m[ WARN] [.]: LOG_STRING: collected warn\x1B[m\n";
117128
inline static const std::string error = "\x1B[m[ERROR] [.]: LOG_STRING: collected error\x1B[m\n";
118129
inline static const std::string fatal = "\x1B[m[FATAL] [.]: LOG_STRING: collected fatal\x1B[m\n";
130+
namespace v2 {
131+
inline static const std::string info = "\x1B[m[INFO] [.]: LOG_STRING: collected info\x1B[m\n";
132+
inline static const std::string warning = "\x1B[m[WARN] [.]: LOG_STRING: collected warn\x1B[m\n";
133+
inline static const std::string error = logstr::error;
134+
inline static const std::string fatal = logstr::fatal;
135+
}
119136
}
120137

121138
namespace custom {

test/default/test_default_basic.cc

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,70 +93,80 @@ TEST(default_basic, lpp_syntax_severity_fatal) {
9393
TEST(default_basic, roslog_syntax_severity_debug) {
9494
LOG_INIT(*test_argv);
9595

96-
std::string output1 = LPP_CAPTURE_STDOUT(ROS_DEBUG("Test"));
97-
ASSERT_EQ(debug, removeNumbersFromString(output1));
96+
std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG("Test"));
97+
bool isEqual = debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output);
98+
EXPECT_TRUE(isEqual);
9899
}
99100

100101
TEST(default_basic, roslog_syntax_severity_debug_stream) {
101102
LOG_INIT(*test_argv);
102103

103104
std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_STREAM("Test"));
104-
ASSERT_EQ(debug, removeNumbersFromString(output));
105+
bool isEqual = debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output);
106+
EXPECT_TRUE(isEqual);
105107
}
106108

107109
TEST(default_basic, roslog_syntax_severity_info) {
108110
LOG_INIT(*test_argv);
109111

110112
std::string output = LPP_CAPTURE_STDOUT(ROS_INFO("Test"));
111-
ASSERT_EQ(info, removeNumbersFromString(output));
113+
bool isEqual = info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output);
114+
EXPECT_TRUE(isEqual);
112115
}
113116

114117
TEST(default_basic, roslog_syntax_severity_info_stream) {
115118
LOG_INIT(*test_argv);
116119

117120
std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_STREAM("Test"));
118-
ASSERT_EQ(info, removeNumbersFromString(output));
121+
bool isEqual = info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output);
122+
EXPECT_TRUE(isEqual);
119123
}
120124

121125
TEST(default_basic, roslog_syntax_severity_warning) {
122126
LOG_INIT(*test_argv);
123127

124128
std::string output = LPP_CAPTURE_STDERR(ROS_WARN("Test"));
125-
ASSERT_EQ(warning, removeNumbersFromString(output));
129+
bool isEqual = warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output);
130+
EXPECT_TRUE(isEqual);
126131
}
127132

128133
TEST(default_basic, roslog_syntax_severity_warning_stream) {
129134
LOG_INIT(*test_argv);
130135

131136
std::string output = LPP_CAPTURE_STDERR(ROS_WARN_STREAM("Test"));
132-
ASSERT_EQ(warning, removeNumbersFromString(output));
137+
bool isEqual = warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output);
138+
EXPECT_TRUE(isEqual);
133139
}
134140

135141
TEST(default_basic, roslog_syntax_severity_error) {
136142
LOG_INIT(*test_argv);
137143

138144
std::string output = LPP_CAPTURE_STDERR(ROS_ERROR("Test"));
139-
ASSERT_EQ(error, removeNumbersFromString(output));
145+
bool isEqual = error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output);
146+
EXPECT_TRUE(isEqual);
140147
}
141148

142149
TEST(default_basic, roslog_syntax_severity_error_stream) {
143150
LOG_INIT(*test_argv);
144151

145152
std::string output = LPP_CAPTURE_STDERR(ROS_ERROR_STREAM("" << "Test"));
146-
ASSERT_EQ(error, removeNumbersFromString(output));
153+
bool isEqual = error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output);
154+
EXPECT_TRUE(isEqual);
147155
}
148156

149157
TEST(default_basic, roslog_syntax_severity_fatal) {
150158
LOG_INIT(*test_argv);
151159

152160
std::string output = LPP_CAPTURE_STDERR(ROS_FATAL("Test"));
153-
ASSERT_EQ(fatal, removeNumbersFromString(output));
161+
bool isEqual = fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output);
162+
EXPECT_TRUE(isEqual);
154163

155164
}
156165

157166
TEST(default_basic, roslog_syntax_severity_fatal_stream) {
158167
LOG_INIT(*test_argv);
159168

160169
std::string output = LPP_CAPTURE_STDERR(ROS_FATAL_STREAM("" << "Test"));
161-
ASSERT_EQ(fatal, removeNumbersFromString(output));
170+
bool isEqual = fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output);
171+
EXPECT_TRUE(isEqual);
162172
}

test/default/test_default_rosprintf.cc

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,103 +13,118 @@ TEST(default_rosprintf, ros_debug) {
1313
LOG_INIT(*test_argv);
1414

1515
std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG(ERROR_MESSAGE, 3.3, 5.5));
16-
ASSERT_EQ(debug, removeNumbersFromString(output));
16+
bool isEqual = debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output);
17+
EXPECT_TRUE(isEqual);
1718
}
1819

1920
TEST(default_rosprintf, ros_debug_once) {
2021
LOG_INIT(*test_argv);
2122

2223
std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_ONCE(ERROR_MESSAGE, 3.3, 5.5));
23-
ASSERT_EQ(debug, removeNumbersFromString(output));
24+
bool isEqual = debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output);
25+
EXPECT_TRUE(isEqual);
2426
}
2527

2628
TEST(default_rosprintf, ros_debug_throttle) {
2729
LOG_INIT(*test_argv);
2830

2931
std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_THROTTLE(1, ERROR_MESSAGE, 3.3, 5.5));
30-
ASSERT_EQ(debug, removeNumbersFromString(output));
32+
bool isEqual = debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output);
33+
EXPECT_TRUE(isEqual);
3134
}
3235

3336
TEST(default_rosprintf, ros_info) {
3437
LOG_INIT(*test_argv);
3538

3639
std::string output = LPP_CAPTURE_STDOUT(ROS_INFO(ERROR_MESSAGE, 3.3, 5.5));
37-
ASSERT_EQ(info, removeNumbersFromString(output));
40+
bool isEqual = info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output);
41+
EXPECT_TRUE(isEqual);
3842
}
3943

4044
TEST(default_rosprintf, ros_info_once) {
4145
LOG_INIT(*test_argv);
4246

4347
std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_ONCE(ERROR_MESSAGE, 3.3, 5.5));
44-
ASSERT_EQ(info, removeNumbersFromString(output));
48+
bool isEqual = info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output);
49+
EXPECT_TRUE(isEqual);
4550
}
4651

4752
TEST(default_rosprintf, ros_info_throttle) {
4853
LOG_INIT(*test_argv);
4954

5055
std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_THROTTLE(1, ERROR_MESSAGE, 3.3, 5.5));
51-
ASSERT_EQ(info, removeNumbersFromString(output));
56+
bool isEqual = info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output);
57+
EXPECT_TRUE(isEqual);
5258
}
5359

5460
TEST(default_rosprintf, ros_warn) {
5561
LOG_INIT(*test_argv);
5662

5763
std::string output = LPP_CAPTURE_STDERR(ROS_WARN(ERROR_MESSAGE, 3.3, 5.5));
58-
ASSERT_EQ(warning, removeNumbersFromString(output));
64+
bool isEqual = warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output);
65+
EXPECT_TRUE(isEqual);
5966
}
6067

6168
TEST(default_rosprintf, ros_warn_once) {
6269
LOG_INIT(*test_argv);
6370

6471
std::string output = LPP_CAPTURE_STDERR(ROS_WARN_ONCE(ERROR_MESSAGE, 3.3, 5.5));
65-
ASSERT_EQ(warning, removeNumbersFromString(output));
72+
bool isEqual = warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output);
73+
EXPECT_TRUE(isEqual);
6674
}
6775

6876
TEST(default_rosprintf, ros_warn_throttle) {
6977
LOG_INIT(*test_argv);
7078

7179
std::string output = LPP_CAPTURE_STDERR(ROS_WARN_THROTTLE(1, ERROR_MESSAGE, 3.3, 5.5));
72-
ASSERT_EQ(warning, removeNumbersFromString(output));
80+
bool isEqual = warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output);
81+
EXPECT_TRUE(isEqual);
7382
}
7483

7584
TEST(default_rosprintf, ros_error) {
7685
LOG_INIT(*test_argv);
7786

7887
std::string output = LPP_CAPTURE_STDERR(ROS_ERROR(ERROR_MESSAGE, 3.3, 5.5));
79-
ASSERT_EQ(error, removeNumbersFromString(output));
88+
bool isEqual = error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output);
89+
EXPECT_TRUE(isEqual);
8090
}
8191

8292
TEST(default_rosprintf, ros_error_once) {
8393
LOG_INIT(*test_argv);
8494

8595
std::string output = LPP_CAPTURE_STDERR(ROS_ERROR_ONCE(ERROR_MESSAGE, 3.3, 5.5));
86-
ASSERT_EQ(error, removeNumbersFromString(output));
96+
bool isEqual = error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output);
97+
EXPECT_TRUE(isEqual);
8798
}
8899

89100
TEST(default_rosprintf, ros_error_throttle) {
90101
LOG_INIT(*test_argv);
91102

92103
std::string output = LPP_CAPTURE_STDERR(ROS_ERROR_THROTTLE(1, ERROR_MESSAGE, 3.3, 5.5));
93-
ASSERT_EQ(error, removeNumbersFromString(output));
104+
bool isEqual = error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output);
105+
EXPECT_TRUE(isEqual);
94106
}
95107

96108
TEST(default_rosprintf, ros_fatal) {
97109
LOG_INIT(*test_argv);
98110

99111
std::string output = LPP_CAPTURE_STDERR(ROS_FATAL(ERROR_MESSAGE, 3.3, 5.5));
100-
ASSERT_EQ(fatal, removeNumbersFromString(output));
112+
bool isEqual = fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output);
113+
EXPECT_TRUE(isEqual);
101114
}
102115

103116
TEST(default_rosprintf, ros_fatal_once) {
104117
LOG_INIT(*test_argv);
105118

106119
std::string output = LPP_CAPTURE_STDERR(ROS_FATAL_ONCE(ERROR_MESSAGE, 3.3, 5.5));
107-
ASSERT_EQ(fatal, removeNumbersFromString(output));
120+
bool isEqual = fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output);
121+
EXPECT_TRUE(isEqual);
108122
}
109123

110124
TEST(default_rosprintf, ros_fatal_throttle) {
111125
LOG_INIT(*test_argv);
112126

113127
std::string output = LPP_CAPTURE_STDERR(ROS_FATAL_THROTTLE(1, ERROR_MESSAGE, 3.3, 5.5));
114-
ASSERT_EQ(fatal, removeNumbersFromString(output));
128+
bool isEqual = fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output);
129+
EXPECT_TRUE(isEqual);
115130
}

0 commit comments

Comments
 (0)