diff --git a/Project.toml b/Project.toml index c45d56b..bff7d61 100644 --- a/Project.toml +++ b/Project.toml @@ -13,7 +13,6 @@ FIGlet = "3064a664-84fe-4d92-92c7-ed492f3d8fae" Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" -Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" @@ -35,7 +34,9 @@ julia = "1.6" [extras] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +IOCapture = "b5f81e59-6552-4d32-b1f0-c071b021bf89" +Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "Documenter"] +test = ["Test", "Documenter", "IOCapture", "Logging"] diff --git a/test/assert_p1_symmetry.jl b/test/assert_p1_symmetry.jl index 0076407..077979f 100644 --- a/test/assert_p1_symmetry.jl +++ b/test/assert_p1_symmetry.jl @@ -1,17 +1,17 @@ module symmetry_test -using Xtals -using Test +using IOCapture, Test, Xtals # Test set for making sure simulations meet certain rules # i.e. frameworks musts be in P1 symmetry to be used in GCMC or Henry # coefficient test @testset "P1 Symmetry Tests" begin - non_P1_framework = Crystal("symmetry_test_structure.cif", convert_to_p1=false) - # Test that an assertion is thrown when trying to replicate a non-P1 - # structure - @test_throws ErrorException replicate(non_P1_framework, (2, 2, 2)) - @test_throws ErrorException replicate(non_P1_framework, (1, 1, 1)) - + IOCapture.capture() do + non_P1_framework = Crystal("symmetry_test_structure.cif", convert_to_p1=false) + # Test that an assertion is thrown when trying to replicate a non-P1 + # structure + @test_throws ErrorException replicate(non_P1_framework, (2, 2, 2)) + @test_throws ErrorException replicate(non_P1_framework, (1, 1, 1)) + end end end diff --git a/test/bonds.jl b/test/bonds.jl index 2929a88..c2b7b26 100644 --- a/test/bonds.jl +++ b/test/bonds.jl @@ -1,6 +1,7 @@ module Bonds_test using Xtals, Graphs, Test, MetaGraphs, LinearAlgebra +import IOCapture.capture irmof1 = Crystal("IRMOF-1.cif") cof102 = Crystal("cof-102.cif") @@ -147,7 +148,9 @@ end @test length(rc[:bonding_rules]) == (n + 1) - println([r for r ∈ bonding_rules if :C == r.species_j][1]) + capture() do + println([r for r ∈ bonding_rules if :C == r.species_j][1]) + end @test true @@ -165,7 +168,9 @@ end @testset "etc" begin temp_vtk_path = tempname() xtal = Crystal("SBMOF-1.cif") - write_bond_information(xtal, temp_vtk_path, center_at_origin=true) + capture() do + write_bond_information(xtal, temp_vtk_path, center_at_origin=true) + end @test isfile(temp_vtk_path * ".vtk") @@ -174,8 +179,10 @@ end write_xyz(xtal, tempname()) all_bonds_temppath = tempname() no_pb_temppath = tempname() - write_bond_information(xtal, all_bonds_temppath) - write_bond_information(xtal, no_pb_temppath, bond_filter=:cross_boundary=>p->!p) + capture() do + write_bond_information(xtal, all_bonds_temppath) + write_bond_information(xtal, no_pb_temppath, bond_filter=:cross_boundary=>p->!p) + end @test all(isfile.([all_bonds_temppath, no_pb_temppath] .* ".vtk")) end diff --git a/test/box.jl b/test/box.jl index 875fc9a..213ec97 100644 --- a/test/box.jl +++ b/test/box.jl @@ -1,8 +1,7 @@ module Box_Test -using Xtals -using LinearAlgebra -using Test +using LinearAlgebra, Test, Xtals +import IOCapture.capture @testset "Box Tests" begin box = Box(11.6, 5.5, 22.9, 90.0 * π / 180, 100.8 * π / 180.0, 90.0 * π / 180.0) @@ -96,11 +95,15 @@ using Test xtal = Crystal("SBMOF-1.cif") vtk_temp = tempname() * ".vtk" - write_vtk(xtal.box, vtk_temp, verbose=true) + capture() do + write_vtk(xtal.box, vtk_temp, verbose=true) + end @test isfile(vtk_temp) # effective test of Base.show(io::IO, box::Box) - println(xtal.box) + capture() do + println(xtal.box) + end @test true end end diff --git a/test/crystal.jl b/test/crystal.jl index 6df5a15..4a26018 100644 --- a/test/crystal.jl +++ b/test/crystal.jl @@ -1,10 +1,7 @@ module Crystal_Test -using Xtals -using LinearAlgebra -using Test -using MetaGraphs, Graphs -using AtomsBase +using AtomsBase, Graphs, LinearAlgebra, MetaGraphs, Test, Xtals +import IOCapture.capture # for test only # if the multi sets are equal, then when you remove duplicates, @@ -126,7 +123,9 @@ end @test true # test verbose printing in empirical_formula - empirical_formula(sbmof1, verbose=true) + capture() do + empirical_formula(sbmof1, verbose=true) + end @test true ##! can this be redirected to a string variable for comparison (and to suppress CLI output during testing?) end diff --git a/test/misc.jl b/test/misc.jl index 3050075..c8f2d65 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -1,11 +1,14 @@ module Misc_Test using Xtals, Test, DataFrames, Graphs, CSV +import IOCapture.capture @testset "Misc Tests" begin xtal = Crystal("SBMOF-1.cif") infer_bonds!(xtal, true) - @test_throws String view_crystal(xtal) # this function really can't be tested programmatically... + capture() do + @test_throws String view_crystal(xtal) # this function really can't be tested programmatically... + end am = rc[:atomic_masses] @test isapprox(am[:H], 1.00794, atol=0.001) diff --git a/test/paths.jl b/test/paths.jl index 28c0def..96e4c63 100644 --- a/test/paths.jl +++ b/test/paths.jl @@ -1,7 +1,6 @@ module Path_Test -using Xtals -using Test +using IOCapture, Test, Xtals @testset "Path Tests" begin @test rc[:atomic_masses][:He] == 4.0026 diff --git a/test/runtests.jl b/test/runtests.jl index 2516898..d1be604 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,28 +1,30 @@ testfiles = [ - "crystal.jl", - "bonds.jl", - "misc.jl", - "matter.jl", - "distance.jl", - "box.jl", - "assert_p1_symmetry.jl", + "crystal.jl" + "bonds.jl" + "misc.jl" + "matter.jl" + "distance.jl" + "box.jl" + "assert_p1_symmetry.jl" "paths.jl" ] -@assert VERSION.major == 1 -@assert VERSION.minor ≥ 6 +@assert (VERSION.major == 1) && (VERSION.minor ≥ 6) "Minimum Julia version not met." + +using Documenter, IOCapture, Logging, Test, Xtals -using Test, Documenter, Xtals, Graphs, MetaGraphs Xtals.banner() for testfile ∈ testfiles @info "Running test/$testfile" - @time include(testfile) + with_logger(NullLogger()) do + include(testfile) + end end # run doctests unless disabled via environment variable if "doctest" ∉ keys(ENV) || ENV["doctest"] ≠ "false" - @time doctest(Xtals) + doctest(Xtals) end @info "Done."