How let Julia create ./test/runtests.jl in my project directory

Viewed 606

How to let Julia terminal generate ./test/runtests.jl automatically ?

(I am currently using a Julia v1.2.0 on MacOS)

What I've tried:

shell> ls
Manifest.toml       Project.toml        src
NewtonRootFinding.ipynb SecantRootFinding.ipynb

shell> cat test/runtest.jl
cat: test/runtest.jl: No such file or directory

(v1.2) pkg> status
    Status `~/.julia/environments/v1.2/Project.toml`
  [7073ff75] IJulia v1.20.0
  [438e738f] PyCall v1.91.2
  [d330b81b] PyPlot v2.8.2

(Prob1) pkg> activate ./test
Activating new environment at `~/..../Prob1/test/Project.toml`

shell> ls
Manifest.toml       Project.toml        src
NewtonRootFinding.ipynb SecantRootFinding.ipynb

(test) pkg> status
    Status `~/.../Prob1/test/Project.toml`
  (empty environment)

(test) pkg> add Test
 Resolving package versions...
  Updating `~/.../Prob1/test/Project.toml`
  [8dfed614] + Test 
  Updating `~/.../Prob1/test/Manifest.toml`
  [2a0f44e3] + Base64 
  [8ba89e20] + Distributed 
  [b77e0a4c] + InteractiveUtils 
  [56ddb016] + Logging 
  [d6f4376e] + Markdown 
  [9a3f8284] + Random 
  [9e88b42a] + Serialization 
  [6462fe0b] + Sockets 
  [8dfed614] + Test 

(test) pkg> status
    Status `~/.../test/Project.toml`
  [8dfed614] Test 

(test) pkg> activate .
Activating environment at `~/.../Prob1/Project.toml`

(Prob1) pkg> status
Project Prob1 v0.1.0
    Status `~/.../Prob1/Project.toml`
  [7073ff75] IJulia v1.20.0
  [438e738f] PyCall v1.91.2
  [d330b81b] PyPlot v2.8.2
  [8dfed614] Test 

(Prob1) pkg> activate ./test
Activating environment at `~/.../Prob1/test/Project.toml`

shell> cat test/runtests.jl
cat: test/runtests.jl: No such file or directory


shell> tree .
.
├── Manifest.toml
├── NewtonRootFinding.ipynb
├── Project.toml
├── SecantRootFinding.ipynb
├── src
│   └── Prob1.jl
└── test
    ├── Manifest.toml
    └── Project.toml

When I typed tree in shell scripting, there is no runtests.jl Julia file in the ./test directory.

I don't know why.

I followed up the Julia Tutorial: https://julialang.github.io/Pkg.jl/v1/creating-packages/index.html

But it didn't work.

2 Answers

Use PkgTemplates.jl

It is actually recommended in the latest version of the Pkg.jl docs but works with all versions of Julia.

Note

The PkgTemplates package offers a very easy, repeatable, and customizable way to generate the files for a new package. We recommend that you use PkgTemplates for creating new packages instead of using the minimal pkg> generate functionality described below.

By my guess, almost the only Julia developers not using it, are ones that don't know about it. (Hopefully this post will help)

Here is a very barebones example with a simple Template.

using PkgTemplates;
template = Template(; user="oxinabox", dir=".");
generate("MyNewPackage", template);

See that it creates a runtests.jl file:

shell> ls ./MyNewPackage/test/
runtests.jl

It also sets up git remotes.

But it can do a lot more. I would at least:

  • Include author and lisence
  • turn on TravisCI for automatic test running
  • Setup Coveralls to report coverage metrics
  • setup GitHubPages for Documenter.jl documentation; so I tend to use something like:
template = Template(;
   user="myusername",
   license="MIT",
   authors=["Lyndon White"],
   dir=".",
   julia_version=v"1.0",
   plugins=[
       TravisCI(),
       Coveralls(),
       GitHubPages(),
   ],
)

@furas is correct. You need to create the ./test/runtests.jl file yourself. It's not created automatically when you use generate command in the package manager.

Related