# Writing a zsh script to test a Julia project

**URL:** <https://discourse.julialang.org/t/writing-a-zsh-script-to-test-a-julia-project/96897>\
**Category:** New to Julia\
**Tags:** testing, shell, scripting\
**Created:** [March 31, 2023, 2:28pm UTC](https://discourse.julialang.org/t/writing-a-zsh-script-to-test-a-julia-project/96897 "2023-03-31T14:28:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmv/32/26323_2.png) [@mmv](https://discourse.julialang.org/u/mmv)\
**Post date:** [March 31, 2023, 2:28pm UTC](https://discourse.julialang.org/t/writing-a-zsh-script-to-test-a-julia-project/96897/1 "2023-03-31T14:28:45Z")

</div>

Hi!

I’d like to write a `zsh` script to automate the testing of a Julia project by

- launching Julia
- starting the `Pkg` environment
- executing the following three commands:
  - activate .
  - add Test
  - test [project\_name]

- exiting the `Pkg` environment
- exiting Julia and return to the shell

If that is feasible, what would be the syntax for achieving this, beyond the usual

```plaintext
#!/bin/zsh
cd [path/to/the/project]
julia --project=[project-name]

```

Can I add arguments to that last line, or do I need to write a separate file? Ideally, this script would simply be called as `test_[project-name]`…

Thanks for suggestions.

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [March 31, 2023, 3:16pm UTC](https://discourse.julialang.org/t/writing-a-zsh-script-to-test-a-julia-project/96897/2 "2023-03-31T15:16:08Z")

</div>

Using the [shebang trick](https://docs.julialang.org/en/v1/manual/faq/#How-do-I-pass-options-to-julia-using-#!/usr/bin/env?) of the FAQ, I would rather write the script in Julia, simply making the required adjustments for it to be runnable from the command-line:

```julia
#!/bin/bash
#=
exec julia --color=yes --startup-file=no "${BASH_SOURCE[0]}" "$@"
=#

using Pkg
Pkg.activate(@ __DIR__ )
Pkg.test()

```

If you want to stick to a pure shell script, then something along those lines should work:

```julia
#!/bin/bash

exec julia --color=yes --startup-file=no -e "
  using Pkg
  Pkg.activate(@ __DIR__ )
  Pkg.test()
"

```

  

> [@mmv](#):
>
> add Test

Why would you like to manage dependencies in such a script? The (possibly test-only) dependencies of your project should be stored in the `*.toml` files acompanying your project; there would normally be no need to add them each time you want to run tests.

---

<div class="post-metadata">

**Author:** ![mmv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmv/32/26323_2.png) [@mmv](https://discourse.julialang.org/u/mmv)\
**Post date:** [March 31, 2023, 11:50pm UTC](https://discourse.julialang.org/t/writing-a-zsh-script-to-test-a-julia-project/96897/3 "2023-03-31T23:50:48Z")

</div>

Hi @ffevotte: Thanks for your input.

I’m dealing with a project involving about a hundred functions and many hundreds of test cases, each implemented as functions too. I already have a script to generate the HTML documentation for the whole project, so I am looking for a similar canned solution to generate all tests using a simple shell script, which can run independently from any other activity going on. It’s essentially a matter of convenience…

Yes, indeed, the `Test` package is mentioned in the `[deps]` of the `Project.toml` file in the test subdirectory… Thanks for clarifying this point.
