Quote:
Originally Posted by RoundTower
This might not be what you want to hear but my view is you should use a library for parsing the command line arguments (getopt? Maybe there is something better or a C++ solution), and use unit tests to test the smallest piece of functionality that you are responsible for.
So if getopt is meant to give the same result for "Filter -o OutputFile -t FilterType InputFile" as for "Filter -o OutputFile InputFile -t FilterType", you don't need to unit test that, you just test that your program behaves as expected when all these arguments are supplied.
I actually do use a library to parse the command line (boost program_options). Still what the operator selects has to be handled correctly. For instance, say the operator specifies an output file where the parent path does not exist. The library parses the output file selection properly and returns what the operator entered. However, what the operator entered needs to be handled correctly. I would think that a unit testing should test that. For example, if the operator enters an invalid path my application should detect when that is the case and inform the operator. A unit test can be written to test that functionality.
Also, applications can interface to libraries incorrectly, mistakenly and those interfaces should be unit tested as well. Parsing the command line isn't really the thing that needs to be tested here and I probably did a poor job of explaining that. What needs to be tested (at least to start) is processing the operator inputs correctly.