# ReTest, module system issues

**URL:** <https://discourse.julialang.org/t/retest-module-system-issues/81885>\
**Category:** General Usage\
**Tags:** question, package, testing, retest\
**Created:** [May 29, 2022, 8:21pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885 "2022-05-29T20:21:21Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [May 29, 2022, 8:21pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/1 "2022-05-29T20:21:21Z")

</div>

Hello, good afternoon,  
I’m trying to test some modules, but I’m having issues with ReTest and the module system. I had this custom modules and is all added to “.” path. RunTests.jl file, I’m getting the

```julia
UndefVarError: float_equality not defined

```

cant understand why

below the source code:

file Primitives.jl

```julia
module Primitives
using Base: +

const EPSILON = 0.0001

function float_equality(a::Float64, b::Float64)::Bool
    if abs(a - b) < EPSILON
        return true
    else
        return false
    end
end

struct Vec3D
    x::Float64
    y::Float64
    z::Float64
end

struct Point3D
    x::Float64
    y::Float64
    z::Float64
end
end

```

file PrimitivesTest.jl

```julia
module PrimitivesTest

include("Primitives.jl")

using .Primitives, ReTest

@testset "float_equality should return true" begin

    @test float_equality(0.1, 0.1222)

end
end

```

file RunTests.jl

```julia
include("PrimitivesTest.jl")
include("Primitives.jl")
using ReTest
retest(Primitives, PrimitivesTest) # error goes here

```

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 29, 2022, 8:33pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/2 "2022-05-29T20:33:01Z")

</div>

You do not explicitly export or import `float_equality`. This your primary issue at the moment.

Also in runtests.jl you should probably not be using `include`. Instead use `using` or `import`.

I recommend closely reading the documentation below. There seems to be significant confusion on the use of `include` and `using` along with a lack of `import` and `export` here.

[https://docs.julialang.org/en/v1/manual/code-loading/](https://docs.julialang.org/en/v1/manual/code-loading/)

---

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [May 29, 2022, 8:35pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/3 "2022-05-29T20:35:39Z")

</div>

Yes. I was in doubt about

> using .Primitives

or

> import .Primitives

but Im already using “using”. There must be a way to add the content in current file first.

---

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [May 29, 2022, 8:39pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/4 "2022-05-29T20:39:42Z")

</div>

Neither worked without import

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/8/683dc46409102db4838a39666261caa009d288f2.png)

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 29, 2022, 8:41pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/5 "2022-05-29T20:41:25Z")

</div>

You need `import .Primitives: float_equality`.

```julia
module PrimitivesTest

include("Primitives.jl")

using .Primitives, ReTest
import .Primitives: float_equality

@testset "float_equality should return true" begin

    @test float_equality(0.1, 0.1222)

end
end

```

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 29, 2022, 8:42pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/6 "2022-05-29T20:42:31Z")

</div>

Alternatively, you need to export it.

```julia
module Primitives
using Base: +

# float_equality will be now be imported automatically when you do `using Primitives`
export float_equality 

const EPSILON = 0.0001

function float_equality(a::Float64, b::Float64)::Bool
    if abs(a - b) < EPSILON
        return true
    else
        return false
    end
end
...
end

```

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 29, 2022, 8:54pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/7 "2022-05-29T20:54:15Z")

</div>

I would be interested in understand your file tree structure and how you run tests. Based on my current understanding, this is how I would arrange your project.

```julia
Primitives/
   Project.toml
   Manifest.toml
   src/Primitives.jl
   test/runtests.jl
   test/PrimitivesTest.jl

```

Primitives.jl:

```julia
module Primitives
using Base: +

export float_equality

const EPSILON = 0.0001

function float_equality(a::Float64, b::Float64)::Bool
    if abs(a - b) < EPSILON
        return true
    else
        return false
    end
end

struct Vec3D
    x::Float64
    y::Float64
    z::Float64
end

struct Point3D
    x::Float64
    y::Float64
    z::Float64
end

```

PrimitivesTest.jl

```julia
module PrimitivesTest

using Primitives, ReTest

@testset "float_equality should return true" begin

    @test float_equality(0.1, 0.1222)

end
end

```

runtests.jl:

```julia
using Primitives, ReTest
include("PrimitivesTest.jl")
using .PrimitivesTest

retest(Primitives, PrimitivesTest)

```

If the current directory were `Primitives`, then I would run `julia --project=. -e "using Pkg; Pkg.test()"`.

---

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [May 29, 2022, 9:03pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/8 "2022-05-29T21:03:36Z")

</div>

Not worked

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/f/6fb91617c495a6cba4fcf8598e79af2bed29dbb6.png)

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 29, 2022, 9:05pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/9 "2022-05-29T21:05:01Z")

</div>

You need to name your project:

[https://pkgdocs.julialang.org/v1/toml-files/#Project.toml](https://pkgdocs.julialang.org/v1/toml-files/#Project.toml)

Here is an example:

> <https://github.com/mkitti/ArrayAllocators.jl/blob/main/Project.toml>

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 29, 2022, 9:06pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/10 "2022-05-29T21:06:48Z")

</div>

The usual way to create this is to use `Pkg.generate("PackageName")` or use [PkgTemplates.jl](https://github.com/invenia/PkgTemplates.jl).

```julia
julia> using Pkg

help?> Pkg.generate
  Pkg.generate(pkgname::String)

  Create a minimal project called pkgname in the current folder. For more featureful package creation, please
  see PkgTemplates.jl.

```

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 29, 2022, 9:08pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/11 "2022-05-29T21:08:41Z")

</div>

If you need to generate a `uuid` by hand, try this:

```julia
julia> using UUIDs

julia> uuid4()
UUID("07a100d5-36e3-4009-9ea3-ad17279780ff")

```

---

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [May 29, 2022, 9:21pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/12 "2022-05-29T21:21:15Z")

</div>

there are a way to run these tests in a simple repl with only an simple activated workspace? There are a lot of issues. Just test it in vscode or rpl for simplicity.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 29, 2022, 9:23pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/13 "2022-05-29T21:23:50Z")

</div>

From the REPL, I would do

```julia
] activate .
] test

```

where the current directory is `Primitives` or perhaps `rtc` in your case.

---

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [May 29, 2022, 9:30pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/14 "2022-05-29T21:30:00Z")

</div>

I’ll need to build a full project from scratch using PakageTemplates.jl… just activate it just not worked.  
I hadnt the filesystem strucure for a project. Using julia ] activate . only give me files in root folder

![image](https://global.discourse-cdn.com/julialang/original/3X/a/d/ad573b833738bf23b1e76837a0b2462d05605d46.png)

---

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [May 29, 2022, 9:30pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/15 "2022-05-29T21:30:32Z")

</div>

its different now when I tryed julia some year ago. Worst is, all book I have about julia is obsolete 😐

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 29, 2022, 9:36pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/16 "2022-05-29T21:36:00Z")

</div>

What is your current file structure?

Since you are not working out of `.julia/dev/` you might need to work on your [`LOAD_PATH`](https://docs.julialang.org/en/v1/base/constants/#Base.LOAD_PATH). Also check the capitalization of `test/runtests.jl`. It should be lower case.

If it’s pre-1.0 (August 8th, 2018), then it’s probably obsolete. There is a book list here:

> **[Books](https://julialang.org/learning/books/)**
>
> The official website for the Julia Language. Julia is a language that is fast, dynamic, easy to use, and open source. Click here to learn more.

---

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [May 29, 2022, 9:49pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/17 "2022-05-29T21:49:53Z")

</div>

I’m rebuilding all my project.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/6/361928619c7644efc8804882e388937db4cbc8b6.png)

Only using “using” did not find the modules

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/6/9617b15abc7d11f4b8725422b5b48a2081c10e6f.png)

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 29, 2022, 10:05pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/18 "2022-05-29T22:05:16Z")

</div>

The problem is that the directory and project is named “rtc”. If you did “using rtc” it would know where to find the `rtc` module.

What is the content of `rtc.jl`?

One way would be to do this as follows:

rtc.jl:

```julia
module rtc
    include("Primitives.jl")
    ...
end

```

PrimitivesTest.jl:

```julia
module PrimitivesTest

using rtc, rtc.Primitives, ReTest

@testset "float_equality should return true" begin

    @test float_equality(0.1, 0.1222)

end
end

```

---

<div class="post-metadata">

**Author:** ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Post date:** [May 29, 2022, 10:48pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/19 "2022-05-29T22:48:40Z")

</div>

if I use Pkg.generate(“rtc”) the folder will aways be called rtc. Tryed the way you did also, and the Primitives cant be found yet.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 29, 2022, 10:50pm UTC](https://discourse.julialang.org/t/retest-module-system-issues/81885/20 "2022-05-29T22:50:52Z")

</div>

Right. When you `Pkg.generate("rtc")`, it is expecting a module called `rtc`. With your current layout, `Primitives` is now a submodule of `rtc`, so we have load `rtc` and then load `rtc.Primitives`. Can it not find `rtc.Primitives`?

[Next page](https://discourse.julialang.org/t/retest-module-system-issues/81885.md?page=2)
