Skip to content

Commit e4d33bb

Browse files
Mal Millermmiller-max
Mal Miller
authored andcommitted
Speed up tests
- Don't activate test package environment - Stop checking registry as much - Remove tests that duplicate testing - Simplify all test packages - Don't clone a fresh registry - we're not testing it
1 parent 7cbd4c6 commit e4d33bb

File tree

32 files changed

+71
-226
lines changed

32 files changed

+71
-226
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "TestReports"
22
uuid = "dcd651b4-b50a-5b6b-8f22-87e9f253a252"
3-
version = "0.5.2"
3+
version = "0.5.3"
44

55
[deps]
66
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

test/recordproperty.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ using TestReports
6666
# Test full packaage
6767
pkg = "TestsWithProperties"
6868
temp_pkg_dir() do tmp
69-
copy_test_package(tmp, pkg)
70-
Pkg.activate(joinpath(tmp, pkg))
69+
Pkg.develop(Pkg.PackageSpec(path=test_package_path(pkg)))
7170
TestReports.test(pkg)
7271
end
7372
logfile = joinpath(@__DIR__, "testlog.xml")
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<testsuites tests="9" failures="0" errors="0"><testsuite name="Math/Multiplication" tests="2" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="0"><testcase name="pass (info lost) (Test 1)" id="_testcase_id_" classname="Math/Multiplication" time="0.0"/><testcase name="pass (info lost) (Test 2)" id="_testcase_id_" classname="Math/Multiplication" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="ID" value="1"/></properties></testsuite><testsuite name="Math/addition/negative addition" tests="2" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="1"><testcase name="pass (info lost) (Test 1)" id="_testcase_id_" classname="Math/addition/negative addition" time="0.0"/><testcase name="pass (info lost) (Test 2)" id="_testcase_id_" classname="Math/addition/negative addition" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="AdditionalNest" value="true"/><property name="ID" value="2"/></properties></testsuite><testsuite name="Math/addition" tests="2" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="2"><testcase name="pass (info lost) (Test 1)" id="_testcase_id_" classname="Math/addition" time="0.0"/><testcase name="pass (info lost) (Test 2)" id="_testcase_id_" classname="Math/addition" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="ID" value="2"/></properties></testsuite><testsuite name="Math" tests="2" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="3"><testcase name="pass (info lost) (Test 1)" id="_testcase_id_" classname="Math" time="0.0"/><testcase name="pass (info lost) (Test 2)" id="_testcase_id_" classname="Math" time="0.0"/><properties><property name="File" value="runtests.jl"/></properties></testsuite><testsuite name="Types" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="4"><testcase name="pass (info lost) (Test 1)" id="_testcase_id_" classname="Types" time="0.0"/><properties><property name="Float" value="0.5"/><property name="Int" value="1"/><property name="String" value="TextTests"/><property name="List" value="[&quot;1&quot;]"/><property name="Symbol" value="asymbol"/></properties></testsuite></testsuites>
2+
<testsuites tests="5" failures="0" errors="0"><testsuite name="Outer/Middle 1" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="0"><testcase name="pass (info lost) (Test 1)" id="_testcase_id_" classname="Outer/Middle 1" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="ID" value="1"/></properties></testsuite><testsuite name="Outer/Middle 2/Inner" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="1"><testcase name="pass (info lost) (Test 1)" id="_testcase_id_" classname="Outer/Middle 2/Inner" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="AdditionalNest" value="true"/><property name="ID" value="2"/></properties></testsuite><testsuite name="Outer/Middle 2" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="2"><testcase name="pass (info lost) (Test 1)" id="_testcase_id_" classname="Outer/Middle 2" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="ID" value="2"/></properties></testsuite><testsuite name="Outer" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="3"><testcase name="pass (info lost) (Test 1)" id="_testcase_id_" classname="Outer" time="0.0"/><properties><property name="File" value="runtests.jl"/></properties></testsuite><testsuite name="Types" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="4"><testcase name="pass (info lost) (Test 1)" id="_testcase_id_" classname="Types" time="0.0"/><properties><property name="Float" value="0.5"/><property name="Int" value="1"/><property name="String" value="TextTests"/><property name="List" value="[&quot;1&quot;]"/><property name="Symbol" value="asymbol"/></properties></testsuite></testsuites>

test/reportgeneration.jl

+22-32
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,25 @@ end
1616

1717
@testset "Runner tests" begin
1818
@testset "Installed packages by name in primary environment" begin
19-
# Pkg.add
19+
# For speed avoid updating registry, we have a fresh one anyway
20+
Pkg.UPDATED_REGISTRY_THIS_SESSION[] = true
21+
# Pkg.add test
2022
Pkg.add(TEST_PKG.name)
2123
test_successful_testrun(() -> TestReports.test(TEST_PKG.name), TEST_PKG.name)
2224
Pkg.rm(TEST_PKG.name)
2325
@test_throws TestReports.PkgTestError TestReports.test(TEST_PKG.name)
24-
25-
# Pkg.develop
26-
pkgname = "PassingTests"
27-
Pkg.develop(Pkg.PackageSpec(path=joinpath(@__DIR__, "test_packages", pkgname)))
28-
test_successful_testrun(() -> TestReports.test(pkgname), pkgname)
29-
Pkg.rm("PassingTests")
3026
end
3127

3228
@testset "Activated projects - TestReports in stacked environment" begin
3329
@testset "by name" begin
3430
# The test run should not fail when passed the name of the project
3531
# that is activated and fail when its deactivated
36-
test_active_package_expected_pass("PassingTests")
32+
temp_pkg_dir() do tmp
33+
pkg = "PassingTests"
34+
path = copy_test_package(tmp, pkg)
35+
Pkg.activate(path)
36+
test_successful_testrun(() -> TestReports.test(pkg), pkg)
37+
end
3738
@test_throws TestReports.PkgTestError TestReports.test(TEST_PKG.name)
3839
end
3940

@@ -57,45 +58,40 @@ end
5758

5859
@testset "Non-package error in runner" begin
5960
temp_pkg_dir() do tmp
60-
pkgname = "PassingTests"
61-
Pkg.develop(Pkg.PackageSpec(path=joinpath(@__DIR__, "test_packages", pkgname)))
61+
pkg = "PassingTests"
62+
Pkg.develop(Pkg.PackageSpec(path=test_package_path(pkg)))
6263
# Pass non-existing argument to julia to make run command fail
63-
@test_throws TestReports.PkgTestError TestReports.test(pkgname, julia_args=`--doesnt-exist`)
64+
@test_throws TestReports.PkgTestError TestReports.test(pkg, julia_args=`--doesnt-exist`)
6465
end
6566
end
6667
end
6768

6869
@testset "Test packages" begin
6970
# Errors
70-
test_active_package_expected_fail("FailedTest")
71-
test_active_package_expected_fail("ErroredTest")
72-
test_active_package_expected_fail("NoTestFile")
71+
test_package_expected_fail("FailedTest")
72+
test_package_expected_fail("ErroredTest")
73+
test_package_expected_fail("NoTestFile")
7374

7475
# Various test dependencies
7576
test_pkgs = [
7677
"TestsWithDeps",
7778
"TestsWithTestDeps"
7879
]
79-
for pkg in test_pkgs
80-
test_active_package_expected_pass(pkg)
81-
end
80+
foreach(test_package_expected_pass, test_pkgs)
8281

8382
# Test file project file tests, 1.2 and above
8483
@static if VERSION >= v"1.2.0"
8584
test_pkgs = [
8685
"TestsWithProjectFile",
8786
"TestsWithProjectFileWithTestDeps"
8887
]
89-
for pkg in test_pkgs
90-
test_active_package_expected_pass(pkg)
91-
end
88+
foreach(test_package_expected_pass, test_pkgs)
9289
end
9390

9491
# Test arguments
9592
temp_pkg_dir() do tmp
9693
pkg = "TestArguments"
97-
copy_test_package(tmp, pkg)
98-
Pkg.activate(joinpath(tmp, pkg))
94+
Pkg.develop(Pkg.PackageSpec(path=test_package_path(pkg)))
9995
test_successful_testrun(() -> TestReports.test(pkg; test_args=`a b`, julia_args=`--quiet --check-bounds=no`), pkg)
10096
test_successful_testrun(() -> TestReports.test(pkg; test_args=["a", "b"], julia_args=`--quiet --check-bounds=no`), pkg)
10197
end
@@ -107,27 +103,21 @@ end
107103
# Single package tests
108104
TestReports.test(TEST_PKG.name)
109105
@test isfile(joinpath(pwd(),"testlog.xml"))
110-
TestReports.test(TEST_PKG.name; logfilename="changedname.xml")
111-
@test isfile(joinpath(pwd(),"changedname.xml"))
112106
new_path = joinpath(pwd(), "NonExistentDir")
113-
TestReports.test(TEST_PKG.name; logfilename="testlog.xml", logfilepath=new_path)
114-
@test isfile(joinpath(new_path,"testlog.xml"))
107+
TestReports.test(TEST_PKG.name; logfilename="changedname.xml", logfilepath=new_path)
108+
@test isfile(joinpath(new_path,"changedname.xml"))
115109
Pkg.rm(TEST_PKG.name)
116110

117111
# Multiple package test
118112
temp_pkg_dir() do tmp
119-
copy_test_package(tmp, "PassingTests")
120-
Pkg.activate(tmp)
121-
Pkg.develop(Pkg.PackageSpec(path=joinpath(tmp, "PassingTests")))
113+
Pkg.develop(Pkg.PackageSpec(path=test_package_path("PassingTests")))
122114
Pkg.add(TEST_PKG.name)
123115
TestReports.test([TEST_PKG.name, "PassingTests"])
124116
@test isfile(joinpath(pwd(),"Example_testlog.xml"))
125117
@test isfile(joinpath(pwd(),"PassingTests_testlog.xml"))
126118
TestReports.test([TEST_PKG.name, "PassingTests"]; logfilename=["testlog1.xml", "testlog2.xml"])
127119
@test isfile(joinpath(pwd(),"testlog1.xml"))
128120
@test isfile(joinpath(pwd(),"testlog2.xml"))
129-
Pkg.rm("PassingTests")
130-
Pkg.rm(TEST_PKG.name)
131121
end
132122

133123
# Errors
@@ -136,7 +126,7 @@ end
136126
@test_throws TypeError TestReports.test(TEST_PKG.name; logfilename=["ThisShouldJustBeAString.xml"])
137127

138128
# Tidy up
139-
rm.(joinpath.(Ref(pwd()), ["testlog.xml", "changedname.xml", "Example_testlog.xml", "PassingTests_testlog.xml", "testlog1.xml", "testlog2.xml"]))
129+
rm.(joinpath.(Ref(pwd()), ["testlog.xml", "Example_testlog.xml", "PassingTests_testlog.xml", "testlog1.xml", "testlog2.xml"]))
140130
rm(new_path, recursive=true)
141131
end
142132

test/runtests.jl

-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,3 @@ include("utils.jl")
1111
@testset "report generation" begin include("reportgeneration.jl") end
1212
@testset "runner internals" begin include("runnerinternals.jl") end
1313
end
14-
15-
# clean up locally cached registry
16-
rm(joinpath(@__DIR__, "registries"); force=true, recursive=true)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module CustomTestSet
22

3-
greet() = print("Hello World!")
4-
53
end # module

test/test_packages/CustomTestSet/test/runtests.jl

-25
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,4 @@ end
4242
@test true
4343
end
4444
@test true
45-
end
46-
47-
# Own time_taken field
48-
mutable struct TimeTakenTestSet <: AbstractTestSet
49-
description::String
50-
results::Vector
51-
time_taken::Int64
52-
end
53-
TimeTakenTestSet(desc) = TimeTakenTestSet(desc, [], -1)
54-
record(ts::TimeTakenTestSet, t) = (push!(ts.results, t); t)
55-
function finish(ts::TimeTakenTestSet)
56-
# If we are a nested test set, do not print a full summary
57-
# now - let the parent test set do the printing
58-
if get_testset_depth() != 0
59-
# Attach this test set to the parent test set
60-
parent_ts = get_testset()
61-
record(parent_ts, ts)
62-
return ts
63-
end
64-
65-
return ts
66-
end
67-
68-
@testset TimeTakenTestSet "ts6" begin
69-
@test true
7045
end

test/test_packages/DefaultTestSet/Project.toml

-9
This file was deleted.

test/test_packages/DefaultTestSet/src/DefaultTestSet.jl

-5
This file was deleted.

test/test_packages/DefaultTestSet/test/runtests.jl

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
module ErroredTest
22

3-
export simple_sum
4-
5-
simple_sum(a, b) = a + b
6-
73
end # module
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
using ErroredTest, Test
22

3-
# Function doesn't exist, will error
4-
@test function_doesnt_exist(1, 2)
3+
@test error("ErroredTest error")
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
module FailedTest
22

3-
export simple_sum
4-
5-
simple_sum(a, b) = a + b
6-
73
end # module
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
using FailedTest, Test
22

3-
# Result will be 3, test will fail
4-
@test simple_sum(1, 2) == 10
3+
@test false
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module NoDescriptionCustomTestSet
22

3-
greet() = print("Hello World!")
4-
53
end # module
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module NoResultsCustomTestSet
22

3-
greet() = print("Hello World!")
4-
53
end # module
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module NoTestFile
22

3-
greet() = print("Hello World!")
4-
53
end # module
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
module PassingTests
22

3-
export simple_sum
4-
5-
simple_sum(a, b) = a + b
6-
73
end # module
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
using PassingTests, Test
22

3-
@test simple_sum(1, 2) == 3
3+
@test true

test/test_packages/TestsWithDeps/Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uuid = "3ef0d59a-7f5b-48e9-8833-7baa3598d41d"
33
version = "0.1.0"
44

55
[deps]
6-
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
6+
Example = "7876af07-990d-54b4-ab0e-23690620f79a"
77

88
[extras]
99
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
module TestsWithDeps
22

3-
using Dictionaries
4-
5-
export create_hash_dict
6-
7-
create_hash_dict(a, b) = Dictionary(["key1", "key2"], [a, b])
3+
using Example
84

95
end # module
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
using TestsWithDeps, Dictionaries, Test
2-
3-
@test create_hash_dict(1, 2) == Dictionary(["key1", "key2"], [1, 2])
1+
using TestsWithDeps, Test
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
module TestsWithProjectFile
22

3-
export simple_sum
4-
5-
simple_sum(a, b) = a + b
6-
73
end # module
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
using TestsWithProjectFile, Test
22

3-
@test simple_sum(1, 2) == 3
3+
@test true
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
module TestsWithProjectFileWithTestDeps
22

3-
export simple_sum
4-
5-
simple_sum(a, b) = a + b
6-
73
end # module
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[deps]
22
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3-
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
3+
Example = "7876af07-990d-54b4-ab0e-23690620f79a"
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
using TestsWithProjectFileWithTestDeps, Dictionaries, Test
2-
3-
results = Dictionary(["result1"], [3])
4-
@test simple_sum(1, 2) == results["result1"]
1+
using TestsWithProjectFileWithTestDeps, Example, Test

test/test_packages/TestsWithProperties/test/runtests.jl

+9-13
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,23 @@ using Test
22
using TestReports
33
using Base.Threads
44

5-
@testset "Math" begin
5+
@testset "Outer" begin
66
recordproperty("File", "runtests.jl")
77

8-
@testset "Multiplication" begin
8+
@testset "Middle 1" begin
99
recordproperty("ID", 1)
10-
@test 1*3 == 3
11-
@test 1*4 == 4
10+
@test true
1211
end
1312

14-
@test 4 % 2 == 0
15-
@test 16 == 16
13+
@test true
1614

17-
@testset "addition" begin
15+
@testset "Middle 2" begin
1816
recordproperty("ID", 2)
19-
@test 1+1 == 2
20-
@test 1+4 == 5
17+
@test true
2118

22-
@testset "negative addition" begin
19+
@testset "Inner" begin
2320
recordproperty("AdditionalNest", true)
24-
@test 1 + -1 == 0
25-
@test 10 + -5 == 5
21+
@test true
2622
end
2723
end
2824
end
@@ -33,5 +29,5 @@ end
3329
recordproperty("Float", 0.5)
3430
recordproperty("List", ["1"])
3531
recordproperty("Symbol", :asymbol)
36-
@test occursin("i", "in")
32+
@test true
3733
end

0 commit comments

Comments
 (0)