# How to test a program with command line parameters

**URL:** <https://discourse.julialang.org/t/how-to-test-a-program-with-command-line-parameters/34901>\
**Category:** New to Julia\
**Tags:** testing\
**Created:** [February 20, 2020, 1:28pm UTC](https://discourse.julialang.org/t/how-to-test-a-program-with-command-line-parameters/34901 "2020-02-20T13:28:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnculpin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnculpin/32/13362_2.png) [@johnculpin](https://discourse.julialang.org/u/johnculpin)\
**Post date:** [February 20, 2020, 1:28pm UTC](https://discourse.julialang.org/t/how-to-test-a-program-with-command-line-parameters/34901/1 "2020-02-20T13:28:03Z")

</div>

Hello,

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?

Thanks,

John C

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [February 20, 2020, 1:53pm UTC](https://discourse.julialang.org/t/how-to-test-a-program-with-command-line-parameters/34901/2 "2020-02-20T13:53:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![johnculpin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnculpin/32/13362_2.png) [@johnculpin](https://discourse.julialang.org/u/johnculpin)\
**Post date:** [February 21, 2020, 9:45am UTC](https://discourse.julialang.org/t/how-to-test-a-program-with-command-line-parameters/34901/3 "2020-02-21T09:45:00Z")

</div>

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.
