SimonKagstrom / kcov

Code coverage tool for compiled programs, Python and Bash which uses debugging information to collect and report data without special compilation options
http://simonkagstrom.github.io/kcov/
GNU General Public License v2.0
709 stars 109 forks source link

configuration: improve getopt_long error reporting #427

Closed perillo closed 5 months ago

perillo commented 5 months ago

Currently, in case of an unrecognized option we get two error messages. The first is printed by getopt_long and the second is printed by kcov error handler.

An additional issue is that the kcov error handler prints optopt, but this value is 0 (NULL character) in this case.

Improve the error handler by using optind to get the offending option. This is done in a separate switch case, instead of the default case. Disable getopt error messages by setting opterr to 0.

Configure getopt_long to report a missing argument using a different error code, so that this can be handled in a separate switch case. Note however that this error is only reported when the option is the last argument.

Update the basic.TooFewArguments and basic.WrongArguments test cases.

TODO

Print useful error message in case of an invalid option argument. This PR will not implement it.

perillo commented 5 months ago

The new test should probably be skipped, since it is preventing full testing.

For the next PRs I plan to improve the Python code running the test suite, so the tests should work without issues.

UPDATE Fixed the bug in #428.

SimonKagstrom commented 5 months ago

That's a nice improvement of the option parsing, thanks a lot!