-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add substring assertion functions #64
Conversation
a356a58
to
620eca2
Compare
#!/usr/bin/env zunit | ||
|
||
@test 'not a substring of' { | ||
assert 'foo' is_not_substring_of 'yellow' |
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.
Can you pass the assertion to run
, and then assert that the $state
is zero and $output
is empty.
See the other tests for examples: https://github.com/molovo/zunit/blob/master/tests/assertions/same_as.zunit
|
||
@test 'not a substring of' { | ||
assert 'foo' is_not_substring_of 'yellow' | ||
} |
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.
Can you also add a test for the failure state, and assert that $output
is 1
and check the error message please? Again, see the same_as
example above.
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.
Ah that's how you check the negative case! Was trying to figure that out :)
@MichaelAquilina thanks for the PR, a very nice addition. I've just asked for some changes to the tests for consistencies sake, and to add tests for the failure state so we can check the error message. See the tests for same_as for an example. Could you also please target the Thanks very much for contributing. |
15feec7
to
fbc0cc7
Compare
@molovo updated and changed base :) |
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.
Perfect. Thanks very much
@@ -0,0 +1,36 @@ | |||
#!/usr/bin/env zunit | |||
|
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.
do we want the empty string to match for is_substring_of
? This case fails in shell script
[[ *''* = "some string" ]]
so in order to be consistent I guess we should also follow that pattern?
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.
Hmm. Interesting case. Actually if you swap the two values round, and run [[ "some string" = *''* ]]
it passes. Not sure how best to deal with it.
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.
In fact, it seems any wildcard on the left side of the assertion will fail, but on the right side it works as expected. I'll dig out the man pages for test
and see if that's expected.
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.
it seems like we cant make this work with the assert function anyway.
assert "" is_substring 'some string'
treats the command as assert is_substring 'some_string'
because the string is empty
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.
Yeah it does. Admittedly, that's a bit of a hack to get the is_empty
and is_not_empty
rules to work, but I couldn't find any better way of doing it because the function doesn't recognise an empty string as an argument.
Looking at the docs here, it reads as string = pattern
, in which case it makes sense that the wildcard only works on the right, and following that assert "" is_substring 'some string'
should pass.
In reality though, if we did make the function pass for an empty value, that would let a lot of false positives fall through the tests when a variable was not defined, so I'm inclined to leave it as it is. Do you agree?
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 agree, there are quite a few complications involved with empty strings so it would be best it it fails and the tests explicitly test an empty string instead
fbc0cc7
to
ff5b882
Compare
Just rebased the branch on |
@MichaelAquilina Excellent. I'll get this merged, and it'll be released with |
Thanks for the help :) |
* Add is_substring_of assert function * Add is_not_substring_of
* Add is_substring_of assert function * Add is_not_substring_of
Ready to review / discuss @molovo