Writing a zsh script to test a Julia project

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

#!/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.

Using the shebang trick 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:

#!/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:

#!/bin/bash

exec julia --color=yes --startup-file=no -e "
  using Pkg
  Pkg.activate(@__DIR__)
  Pkg.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.

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.