I have written a program that accepts command line arguments e.g.
$ julia compiler.jl filename1
where “filename1” could be the file to compile or a directory name where all the code resides.
What I was wondering is, how do I write a runtests.jl file to test how the command line parameters are handled?
For example, if an invalid filename is specified I can throw an error and then in runtest.jl use “@test_throws” to check this happens, but how do I tell runtests.jl what parameter to use?
The command-line arguments land in the vector
ARGS. Presumably you can add/remove stuff to/from there and then run your functions.
But probably it’s would be better if you have one ARGS-parsing function which takes a vector as input. When running normally, this vector will be
ARGS but when testing you can make your own vectors to use as input. Any other function in your code should then not depend on
ARGS anymore but take whatever the ARGS-parsing function spits out.
Thanks for the response mauro3. I agree that it seems the best/only way to test it would be to have a separate function to handle the ARGS processing.