-
Notifications
You must be signed in to change notification settings - Fork 124
[ur] Improve logger env var handling #438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
source/common/ur_util.hpp
Outdated
| auto is_quoted = [&value]() { | ||
| return (value.front() == '\'' && value.back() == '\'') || | ||
| (value.front() == '"' && value.back() == '"') | ||
| ? true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for ? true : false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, thanks.
| endif() | ||
| if(NOT DEFINED MATCH_FILE) | ||
| message(FATAL_ERROR "MATCH_FILE needs to be defined") | ||
| # Process variables passed to the script |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I like it this way. I'd rather have just one way of building tests with match files. But let's leave it for now.
cmake/match.cmake
Outdated
| # In 'nofile' mode, check if the OUT_FILE exists and exit the script | ||
| if(${MODE} STREQUAL "nofile") | ||
| if(EXISTS ${OUT_FILE}) | ||
| file(REMOVE ${OUT_FILE}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you souldn't remove random files like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved removal of files to tests set up. However, the output file is not removed after tests, rather before them, so the out file will exist after running the last test.
cmake/match.cmake
Outdated
| file(REMOVE ${OUT_FILE}) | ||
| message(FATAL_ERROR "Failed: File ${OUT_FILE} should not be created") | ||
| else() | ||
| message("Passed: Default logger has been constructed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make the message generic ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point :)
2a942f9 to
2871f48
Compare
2871f48 to
a538d96
Compare
There is no guarantee that they run in order, just that the first test is set to finish before this one. Between these two other tests can run. Hence, I restructured a bit tests to be run from a cmake wrapper script using |
a538d96 to
4b0af3f
Compare
cmake/match.cmake
Outdated
| message(FATAL_ERROR "TEST_FILE needs to be defined") | ||
| # Process variables passed to the script | ||
| if(NOT DEFINED MODE) | ||
| message(FATAL_ERROR "MODE needs to be defined. Possible values: 'binary', 'file'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think really the difference is what we match against, some specified file or stdout, right? If so, I think it would be better to call these modes 'stdout' and 'file'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| file(REMOVE ${OUT_FILE}) | ||
| endif() | ||
|
|
||
| execute_process( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, this is exactly what the match.cmake does. So what you are effectively doing is creating a wrapper with the same functionality that is being disabled (by mode 'binary') in the main script?
Again, I'm not sure I fully understand, but if all you are trying to do is match against different output destination (stdout, stderr, file), then it'd be easier to create that argument in the original match script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wrapper removes also files before and after the test. I'm moving for now such a removal. It also allows for not having a file at all, in which case compare argument in cmake.match script would fail and I would have to have some other check introduced there (with ifdef) instead. Perhaps python script from #444 would simplify things, I'll rebase to it.
test/unit/logger/CMakeLists.txt
Outdated
| ENVIRONMENT ${env_var}\;GTEST_FILTER=*${test_case}\;GTEST_BRIEF=1 | ||
| ) | ||
|
|
||
| file(READ ${match_file} MATCH_STRING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added support for regex matches in #444
65fc267 to
a0484b9
Compare
Add tests for validation of the global logger object setup from an environment variable.
source/common/ur_util.hpp
Outdated
| ex_ss << "Wrong format of the " << env_var_name << " environment variable!" | ||
| << " Proper format is: " | ||
| ex_ss << "Wrong format of the " << env_var_name | ||
| << " environment variable: '" << env_var_value << "'\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wording might be a bit confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rephrased a bit
source/common/ur_util.hpp
Outdated
| ex_ss << "Wrong format of the " << env_var_name | ||
| << " environment variable: '" << env_var_value << "'\n" | ||
| << "Proper format is: " | ||
| "ENV_VAR=\"param_1:value_1,value_2;param_2:value_1"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's \" missing at the end of the exception string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
source/common/ur_util.hpp
Outdated
| if (value.empty()) { | ||
| throw_wrong_format_map(env_var_name); | ||
| if (value.empty() || | ||
| ((value.find(':') != std::string::npos) && !is_quoted())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you have an anonymous function for is_quoted you might want to create has_colon for (value.find(':') != std::string::npos).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added has_colon(). Also moved lambdas out of the while loop.
a0484b9 to
93754d2
Compare
- catch an exception thrown by env var parsing function - check for unknown parameters set in an env var - fix wrong logger level when creating logger from an environment variable with an "error" level set - handle Windows absolute path to logfile properly - extend failure messages - strict check for standard output logger 'output' option
Add tests for validation of the global logger object setup from
an environment variable. Improve logger env var handling.