# How to test an app at the REPL

**URL:** https://discourse.julialang.org/t/how-to-test-an-app-at-the-repl/40510
**Category:** New to Julia
**Created:** [May 31, 2020, 1:39pm UTC](https://discourse.julialang.org/t/how-to-test-an-app-at-the-repl/40510 "2020-05-31T13:39:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![German\_Salazar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/german_salazar/32/11994_2.png) [@German\_Salazar](https://discourse.julialang.org/u/German_Salazar)
#### Post date: [May 31, 2020, 1:39pm UTC](https://discourse.julialang.org/t/how-to-test-an-app-at-the-repl/40510/1 "2020-05-31T13:39:49Z")

</div>

Say, I want to develop a standalone, compiled application; after reading about various options, I settled on creating a project via `Pkg.generate`.

Now, I have a project structure with `Manifest.toml` and `Project.toml` files, and the program entry point under `MyProgram/src/MyProgram.jl`

At this very moment, all the program does is parse command line arguments; let’s say `MyProgram.jl` looks like this:

```julia
module MyProgram
    using ArgParse
    function main()
    ...
    end
end

```

This minimal program:

- compiles fine with `PackageCompiler.create_app()`
- runs from the command line just fine and correctly processes command line arguments

What are the steps that I need to take to end up at the REPL with the correct environment, so that I can easily edit my program and test it over and over? Meaning, without having to re-start Julia?

In particular, I would like to change the “comand line arguments” (while in REPL) and call main() over and over.

---

<div class="post-metadata">

### Author: ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)
#### Post date: [May 31, 2020, 4:07pm UTC](https://discourse.julialang.org/t/how-to-test-an-app-at-the-repl/40510/2 "2020-05-31T16:07:25Z")

</div>

There may be a way to do what you want, but when faced with this problem in the past, I have changed the structure of the code to make REPL work simpler.

```julia
module MyProgram
using ArgParse

function do_stuff(args)
  # This function is the top-level of the program's functionality
  # and is easily called from the REPL
end

function parse_args()
  # Argument parsing happens here, this returns a parsed args structure
  # that can be passed to do_stuff()
end

function main()
  args = parse_args()
  do_stuff(args)
end

end

```

If creating `args` manually get tedious, it is often helpful to write some tools to create a starting point, I often create a `test/REPL_tests.jl` that has functions to mock up useful sets of `args` and then `includet` that file.

---

<div class="post-metadata">

### Author: ![zachmatson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zachmatson/32/9397_2.png) [@zachmatson](https://discourse.julialang.org/u/zachmatson)
#### Post date: [June 9, 2020, 9:06pm UTC](https://discourse.julialang.org/t/how-to-test-an-app-at-the-repl/40510/3 "2020-06-09T21:06:40Z")

</div>

If you want to change the command line arguments while Julia is running, you can edit the variable `ARGS`.  
Trying to assign a value to the variable probably won’t do what you want, but this should work:

```julia
clear!(ARGS)
append!(ARGS, ["foo", "--bar"])

```

---

<div class="post-metadata">

### Author: ![zachmatson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zachmatson/32/9397_2.png) [@zachmatson](https://discourse.julialang.org/u/zachmatson)
#### Post date: [June 9, 2020, 9:15pm UTC](https://discourse.julialang.org/t/how-to-test-an-app-at-the-repl/40510/4 "2020-06-09T21:15:12Z")

</div>

For an example:

```julia
julia> using ArgMacros

julia> function main()
           @beginarguments begin
               @argumentflag verbose "-v"
               @positionaldefault Int 1 x
           end

           println(x, verbose)
       end
main (generic function with 1 method)

julia> ARGS
0-element Array{String,1}

julia> main()
1false

julia> append!(ARGS, ["3", "-v"])
2-element Array{String,1}:
 "3"
 "-v"

julia> main()
3true

julia> empty!(ARGS)
0-element Array{String,1}

julia> push!(ARGS, "4")
1-element Array{String,1}:
 "4"

julia> main()
4false

```
