On Sun Sep 01 11:14:13 2019, DROLSKY wrote:
Show quoted text> It'd be nice if the perltidy command supported some sort of `--check`
> flag where it simply reported whether the file(s) in question where
> already tidy.
>
> If this seems like a good idea I could probably work on a PR.
Dave,
The cleanest way I see to implement something like this is to add a flag which will produce an error message if the output differs from the input. This would be a simple update and completely independent of all other input flags. I wrote a test version which accepted a new flag
tentatively named '--assert-unchanged', which means that the output is expected to be the same as the input.
The way it works is that, when the flag is set, an MD5 sum is made for the input stream and for the output stream, and if they differ an error message is output.
It might be used like this to check some file named 'infile':
perltidy --assert-unchanged myfile -st -se >/dev/null 2>err.out
Here I've sent the output to /dev/null, but it could also be retained as usual if desired. If the output differs from the input, then err.out will exist and would contain a line like
myfile: '--assert-unchanged' is set but output differs from input
If there is no error output, then the input and output files are identical. If there is an error output, then something is wrong but it might be something other than the output and input being different.
If this seems useful I can clean it up and include it.
Steve