Skip Menu |

This queue is for tickets about the Perl-Tidy CPAN distribution.

Report information
The Basics
Id: 130425
Status: resolved
Priority: 0/
Queue: Perl-Tidy

People
Owner: Nobody in particular
Requestors: DROLSKY [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Wishlist: Check mode
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.
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
On 2019-09-03 19:16:07, SHANCOCK wrote: Show quoted text
> On Sun Sep 01 11:14:13 2019, DROLSKY wrote:
> > 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.
Yes, that would be perfect. My one big request is that perltidy should exit with a non-zero exit code when this error occurs.
On Tue Sep 03 20:28:03 2019, DROLSKY wrote: Show quoted text
> On 2019-09-03 19:16:07, SHANCOCK wrote:
> > On Sun Sep 01 11:14:13 2019, DROLSKY wrote:
> > > 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.
> > Yes, that would be perfect. My one big request is that perltidy should > exit with a non-zero exit code when this error occurs.
Yes, it will. There is an update for that in the next release (probably mid-October).
Version 20190915 has this update