在我的Advent of Code repository我从去年开始就有了一个实用程序库,今年也一直在使用其中的东西。
今年我想添加第二个,以便更快地加载输入文件。由于某种原因,单元测试和 using
它适用于旧库,但不适用于第二个库。
我尝试尽可能地统一这两个文件夹,直到 Project.toml
现在相等。
two directories看起来像这样(ProblemParser
失败,Utils
工作):
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
将它们添加到 Project ( Manifest ) 工作正常(其他内容省略):
(AoC 2021) pkg> status Status `~/src/me/AoC/21/Project.toml` [16064a1e] ProblemParser v0.1.0 `../ProblemParser` [c4255648] Utils v0.1.0 `../Utils`
但是尝试使用 ProblemParser
并不顺利。
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
尝试运行测试时会发生相同的是/否。
(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
两者有什么区别?是什么导致一个有效而另一个无效?
我就是没看到。
最佳答案
啊,您在 src/ProblemParser.jl
中定义了错误的模块名称 - 第一行是 module ProjectParser
而不是 module ProblemParser
.
关于unit-testing - 请解释我们应该如何测试 Julia 库以及为什么两个中断之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70395522/