Add a matcher for file contents equality/difference#138
Add a matcher for file contents equality/difference#138AntoniMarcinek wants to merge 2 commits intoshellspec:masterfrom
Conversation
|
Thanks for contribution. Eventually I want to merge this, but there are a few things to do. First, this is a matcher to make sure the files are identical. It would be good to be able to see the differences in diff format, but It is better to output only if there is a difference or not in this PR. About cmpI try not to increase the number of dependent commands whenever possible, but I think # dash silently ignores the null character
dash -c '[ "_$(printf "\0")_" = "__" ]; echo $?'
0
# bash ignores the null character with warning
bash -c '[ "_$(printf "\0")_" = "__" ]; echo $?'
bash: warning: command substitution: ignored null byte in input
0
# only zsh can handle null character
$ zsh -c '[ "_$(printf "\0")_" = "__" ]; echo $?'
1Therefore, it makes sense to use docker run -it fedora:32 /bin/sh
sh-5.0# cmp
sh: cmp: command not foundIn reality I don't think this will be a problem, but I want to avoid it if possible. Fortunately, About DSL
I think this is better. It's not as long as About diffDo not use a There are several implementations of diffs, such as It will take some time the implementation using |
About cmpDo I understand correctly that with the fallback the comparison should be done like so that the strings are compared, but in a way which assures that the null character is not ignored? I am not sure if am able to properly (i.e. in the shell-independent way) implement the check for existence of About DSLThis also looks good to me. Unfortunately I am not sure how to implement it, because I don't really understand the matcher design - how this is called, what different functions in Specifically what to do with Is there a way to assert that the subject is About diffThis looks clear from my side. I do have some questions to #112 though, but will comment there. |
The purpose of the PR
This pull request adds a matcher to be used in asserting equality/difference of files. The intent is to support something like this:
The PR's purpose is to start the discussion of the the above use case on something which already works.
Note that other possibilities are with
or
but the first provides too verbose and unreadable message, while the second one does not add the diff to the failure message.
Potential problems with this solution
It adds dependence on
cmpanddiffI have no idea what is the significance of this, i.e. if there are platforms lacking these tools.I am aware that the name of the matcher is not very pretty. Maybe
diff-equalorcontents-equalwould be better? Is the-character allowed in the DSL? I was considering the below, but found out none of these is permitted/gives the expected outcome: