Search code examples
unit-testingmodulejuliaimporterrordirectory-structure

Please explain how we're supposed to test Julia libraries and why one of two breaks


In my Advent of Code repository I've had a utility library since last year and have been using stuff from that also this year.

This year I wanted to add a second one for loading the input files quicker. For some reason unittests and using it works for the old library but not for the second.

I tried to unify the two folders as much as possible until the Project.toml for instance are equal now.

The two directories look like this (ProblemParser failing and Utils working):

ProblemParser ⛔
├── Manifest.toml
├── Project.toml
├── src
│  └── ProblemParser.jl
└── test
   ├── Manifest.toml
   ├── Project.toml
   └── runtests.jl

Utils ✅
├── Manifest.toml
├── Project.toml
├── src
│  └── Utils.jl
└── test
   ├── Manifest.toml
   ├── Project.toml
   └── runtests.jl

Adding them to the Project (Manifest) works fine (other stuff left out):

(AoC 2021) pkg> status
      Status `~/src/me/AoC/21/Project.toml`
  [16064a1e] ProblemParser v0.1.0 `../ProblemParser`
  [c4255648] Utils v0.1.0 `../Utils`

However trying to use ProblemParser doesn't go so well.

julia> using Utils

julia> # that worked

julia> using ProblemParser
ERROR: KeyError: key ProblemParser [16064a1e-6b5f-4a50-97c7-fe66cda9553b] not found
Stacktrace:
 [1] getindex
   @ ./dict.jl:481 [inlined]
 [2] root_module
   @ ./loading.jl:1056 [inlined]
 [3] require(uuidkey::Base.PkgId)
   @ Base ./loading.jl:1022
 [4] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:997

The same yes/no happens when trying to run the tests.

(AoC 2021) pkg> activate ../Utils/
  Activating project at `~/src/me/AoC/Utils`

(Utils) pkg> test
     Testing Utils
      Status `/tmp/jl_AGawpC/Project.toml`
  [c4255648] Utils v0.1.0 `~/src/me/AoC/Utils`
  [8dfed614] Test `@stdlib/Test`
      Status `/tmp/jl_AGawpC/Manifest.toml`
  [79e6a3ab] Adapt v3.3.1

  ----- 8< snipped 8< -----

  [4536629a] OpenBLAS_jll `@stdlib/OpenBLAS_jll`
  [8e850b90] libblastrampoline_jll `@stdlib/libblastrampoline_jll`
     Testing Running tests...
Test Summary:      | Pass  Total
@something_nothing |   15     15
     Testing Utils tests passed

(Utils) pkg> activate ../ProblemParser/
  Activating project at `~/src/me/AoC/ProblemParser`

(ProblemParser) pkg> test
     Testing ProblemParser
      Status `/tmp/jl_6v5Y3D/Project.toml`
  [16064a1e] ProblemParser v0.1.0 `~/src/me/AoC/ProblemParser`
  [8dfed614] Test `@stdlib/Test`
      Status `/tmp/jl_6v5Y3D/Manifest.toml`
  [16064a1e] ProblemParser v0.1.0 `~/src/me/AoC/ProblemParser`
  [2a0f44e3] Base64 `@stdlib/Base64`

  ----- 8< snipped 8< -----

  [9e88b42a] Serialization `@stdlib/Serialization`
  [8dfed614] Test `@stdlib/Test`
     Testing Running tests...
ERROR: LoadError: ArgumentError: Package ProjectParser not found in current path:
- Run `import Pkg; Pkg.add("ProjectParser")` to install the ProjectParser package.

Stacktrace:
 [1] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:967
 [2] include(fname::String)
   @ Base.MainInclude ./client.jl:451
 [3] top-level scope
   @ none:6
in expression starting at /home/tsbr/src/me/AoC/ProblemParser/test/runtests.jl:1
ERROR: Package ProblemParser errored during testing

What is the difference between the two? What makes one work and the other not?
I just don't see it.


Solution

  • Ah, you have the module name defined wrong in src/ProblemParser.jl - the first line is module ProjectParser instead of module ProblemParser.