Skip to content
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

Merged
merged 2 commits into from
Jul 3, 2017

Conversation

MichaelAquilina
Copy link
Contributor

@MichaelAquilina MichaelAquilina commented Jul 3, 2017

Ready to review / discuss @molovo

@MichaelAquilina MichaelAquilina force-pushed the is_substring_of branch 3 times, most recently from a356a58 to 620eca2 Compare July 3, 2017 17:55
@MichaelAquilina MichaelAquilina changed the title Add is_substring_of assert function Add substring assertion functions Jul 3, 2017
#!/usr/bin/env zunit

@test 'not a substring of' {
assert 'foo' is_not_substring_of 'yellow'
Copy link
Member

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'
}
Copy link
Member

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.

Copy link
Contributor Author

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

@molovo
Copy link
Member

molovo commented Jul 3, 2017

@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 next branch rather than master, so I can get this in the next release?

Thanks very much for contributing.

@MichaelAquilina MichaelAquilina changed the base branch from master to next July 3, 2017 20:21
@MichaelAquilina MichaelAquilina force-pushed the is_substring_of branch 2 times, most recently from 15feec7 to fbc0cc7 Compare July 3, 2017 20:33
@MichaelAquilina
Copy link
Contributor Author

@molovo updated and changed base :)

Copy link
Member

@molovo molovo left a 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

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Contributor Author

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

@MichaelAquilina
Copy link
Contributor Author

Just rebased the branch on next

@molovo
Copy link
Member

molovo commented Jul 3, 2017

@MichaelAquilina Excellent. I'll get this merged, and it'll be released with v0.8.0. Thanks for your contribution.

@molovo molovo merged commit e08cd1f into zunit-zsh:next Jul 3, 2017
@MichaelAquilina
Copy link
Contributor Author

Thanks for the help :)

@MichaelAquilina MichaelAquilina deleted the is_substring_of branch July 3, 2017 21:02
@molovo molovo mentioned this pull request Jul 3, 2017
11 tasks
molovo pushed a commit that referenced this pull request Jul 6, 2017
* Add is_substring_of assert function

* Add is_not_substring_of
molovo pushed a commit that referenced this pull request Jul 10, 2017
* Add is_substring_of assert function

* Add is_not_substring_of
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.

2 participants