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
UndefVarError: float_equality not defined
cant understand why
below the source code:
file Primitives.jl
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
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
include("PrimitivesTest.jl")
include("Primitives.jl")
using ReTest
retest(Primitives, PrimitivesTest) # error goes here
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.
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
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
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.
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
module PrimitivesTest
using Primitives, ReTest
@testset "float_equality should return true" begin
@test float_equality(0.1, 0.1222)
end
end
runtests.jl:
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()".
The usual way to create this is to use Pkg.generate("PackageName") or use PkgTemplates.jl.
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.
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.
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
Since you are not working out of .julia/dev/ you might need to work on your 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:
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?