Skip to content

Conversation

@PatKamin
Copy link
Contributor

Add tests for validation of the global logger object setup from
an environment variable. Improve logger env var handling.

auto is_quoted = [&value]() {
return (value.front() == '\'' && value.back() == '\'') ||
(value.front() == '"' && value.back() == '"')
? true
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

# 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})
Copy link
Contributor

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.

Copy link
Contributor Author

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.

file(REMOVE ${OUT_FILE})
message(FATAL_ERROR "Failed: File ${OUT_FILE} should not be created")
else()
message("Passed: Default logger has been constructed")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make the message generic ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point :)

@PatKamin PatKamin force-pushed the logger-env-var-tests branch from 2a942f9 to 2871f48 Compare April 14, 2023 09:56
@PatKamin PatKamin force-pushed the logger-env-var-tests branch from 2871f48 to a538d96 Compare April 14, 2023 13:51
@PatKamin
Copy link
Contributor Author

Are you guaranteed that these tests are going to run in order? Why not just run the test in the match script?

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 execute_process() command.

@PatKamin PatKamin force-pushed the logger-env-var-tests branch from a538d96 to 4b0af3f Compare April 14, 2023 13:58
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'")
Copy link
Contributor

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'.

Copy link
Contributor Author

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(
Copy link
Contributor

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.

Copy link
Contributor Author

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.

ENVIRONMENT ${env_var}\;GTEST_FILTER=*${test_case}\;GTEST_BRIEF=1
)

file(READ ${match_file} MATCH_STRING)
Copy link
Contributor

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

@PatKamin PatKamin force-pushed the logger-env-var-tests branch 3 times, most recently from 65fc267 to a0484b9 Compare April 20, 2023 10:17
Add tests for validation of the global logger object setup from
an environment variable.
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"
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rephrased a bit

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";
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if (value.empty()) {
throw_wrong_format_map(env_var_name);
if (value.empty() ||
((value.find(':') != std::string::npos) && !is_quoted())) {
Copy link
Contributor

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).

Copy link
Contributor Author

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.

@PatKamin PatKamin force-pushed the logger-env-var-tests branch from a0484b9 to 93754d2 Compare April 20, 2023 12:08
- 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
@pbalcer pbalcer merged commit 1382907 into oneapi-src:main Apr 20, 2023
@PatKamin PatKamin deleted the logger-env-var-tests branch June 26, 2024 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants