Workflow for Testing Packages

Hi there,

I’m new to Julia and I’m currently developing a new package. In order to set up a testing suite, I followed the “tutorial” in the Docs.

However even with this simple example I’m getting following error for every single test:

Test threw exception
  Expression: 2 == simple_add(1, 1)
  UndefVarError: simple_add not defined
   [1] macro expansion
     @ /Applications/ [inlined]
   [2] macro expansion
     @ ~/Desktop/Example/test/math_tests.jl:2 [inlined]
   [3] macro expansion
     @ /Applications/ [inlined]
   [4] top-level scope
     @ ~/Desktop/Example/test/math_tests.jl:2

From my understanding runtests.jl should be able to find Example.jl by itself and include it.
But even after including Example.jl manually I get the same error.

Didn’t find anybody having the same problem online so I’m posting it here…

Thanks for the help!

I think the example in the docs might be wrong because it doesn’t export the functions it defines. Basically, if you want to use the function simple_add outside of the Example module, there are three options:

  • hope that Example contains the statement export simple_add
  • prefix the function call with Example.simple_add
  • replace using Example with using Example: simple_add

Can anyone confirm that the docs is indeed wrong?
The Example.jl package on GitHub does include exports:

There is no simple_add function in that package. The functions it exports and test are hello and domath.

(the example seems ok, I mean)

The documentation I see - Unit Testing · The Julia Language - doesn’t include any export statements, therefore the error jeffzwe observes.

1 Like

Indeed, what I meant is that the Examples.jl package on the JuliaLang GitHub repo has an export, but the Example module on the test docs page doesn’t, and that second part seems wrong to me (regardless of the fact that they have different contents). I’ll open a PR

1 Like

In case core devs see this, it’s a 1-line PR: Add exports to `Example` module for the test workflow in the docs by gdalle · Pull Request #50459 · JuliaLang/julia · GitHub

Thanks! This did the trick

1 Like