add a test case that calls the default_fmt_val method#7
add a test case that calls the default_fmt_val method#7szabgab wants to merge 4 commits intoahmadbky:masterfrom
Conversation
There was a problem hiding this comment.
Hi, thanks for contributing.
Regarding the test relevance, I think this one looks more like an integration test, since it doesn't test only the default_val_fmt method, but also makes calls to methods like define(), init() and get(), and these should be tested in a separate unit.
Also, the tests seem more related to the make_config! macro, so they should be placed in the macros module.
Moreover, the declaration of the struct MyConfig should be made in the body of the test function, for better clarity (and avoid already taken identifier if having multiple test functions).
| } | ||
| let config = MyConfig::define(); | ||
| config.init(); | ||
| assert_eq!(config.url.get(), "asd"); |
There was a problem hiding this comment.
Move the test of the init() and get() calls into a separate unit.
Also, prefer using the with_env function from the tests module, to setup the $MY_URL env var, for more consistency with the other unit tests.
Make sure to use catch_unwind since the calls to init() and get() may panic.
| assert_eq!(config.url.get_descriptor().var_name, "MY_URL"); | ||
| assert_eq!(config.url.get_descriptor().default_val_fmt, None); | ||
|
|
||
| let url = config.url.default_fmt_val("hi"); |
There was a problem hiding this comment.
Instead of overriding the config here, make another unit test in a separate function that calls the make_config! macro, which specifies default_val_fmt, and test the resulting descriptor.
You could also make this to test description, and make some tweaks between it and default_val_fmt.
|
IMHO integration tests are good as that make it easier for a reader of the code to see how can it be used. |
You're right, we definitely should add integration tests. I am just nitpicky because I find the test relevant, because it affects more what the macro generates, than what the generated code executes in behind. However IMHO, such test makes more sense as unit tests than integration tests. We could do both, I'm just talking about testing That said, if you think this would make too many changes in this PR, you can move the test in a new |
|
I tried to move it to a new If I understand correctly this is because both of the Am I misunderstanding something? As I understand Alternatively the tests could use the and I am updating the PR in that direction. |
|
You were right about the visibility of the fields And yes, I agree on the fact that it's a bit confusing that |
No description provided.