@@ -4,33 +4,29 @@ using Test
44using Dates
55using LibGit2
66using Random
7+ using Pkg
78
89const BENCHMARK_DIR = joinpath (@__DIR__ , " .." , " benchmark" )
910
1011function temp_pkg_dir (fn:: Function ; tmp_dir= joinpath (tempdir (), randstring ()),
1112 remove_tmp_dir:: Bool = true , initialize:: Bool = true )
1213 # Used in tests below to set up and tear down a sandboxed package directory
13- withenv (" JULIA_PKGDIR" => tmp_dir) do
14- @test ! isdir (Pkg. dir ())
15- try
16- if initialize
17- Pkg. init ()
18- @test isdir (Pkg. dir ())
19- Pkg. resolve ()
20- else
21- mkpath (Pkg. dir ())
22- end
23- fn ()
24- finally
25- remove_tmp_dir && try rm (tmp_dir, recursive= true ) end
26- end
14+ try
15+ # TODO (nhdaly): Is this right??
16+ Pkg. generate (tmp_dir)
17+ Pkg. activate (tmp_dir)
18+ Pkg. instantiate ()
19+ fn ()
20+ finally
21+ # TODO (nhdaly): Is there a way to re-activate the previous environment?
22+ Pkg. activate ()
23+ remove_tmp_dir && try rm (tmp_dir, recursive= true ) catch end
2724 end
2825end
2926
3027function test_structure (g)
3128 @test g |> keys |> collect |> Set == [" utf8" , " trigonometry" ] |> Set
3229 @test g[" utf8" ] |> keys |> collect |> Set == [" join" , " plots" , " replace" ] |> Set
33- @test g[" utf8" ][" plots" ] |> keys |> collect == [" fnplot" ]
3430
3531 _keys = Set (vec ([string ((string (f), x)) for x in (0.0 , pi ), f in (sin, cos, tan)]))
3632 @test g[" trigonometry" ][" circular" ] |> keys |> collect |> Set == _keys
@@ -48,17 +44,19 @@ const TEST_PACKAGE_NAME = "Example"
4844
4945# Set up a test package in a temp folder that we use to test things on
5046tmp_dir = joinpath (tempdir (), randstring ())
51- old_pkgdir = Pkg. dir ()
47+ old_pkgdir = Pkg. depots ()[ 1 ]
5248
5349temp_pkg_dir (;tmp_dir = tmp_dir) do
5450 test_sig = LibGit2. Signature (" TEST" , " TEST@TEST.COM" , round (time (); digits= 0 ), 0 )
55- Pkg. add (TEST_PACKAGE_NAME)
51+ full_repo_path = joinpath (tmp_dir, TEST_PACKAGE_NAME)
52+ Pkg. generate (full_repo_path)
53+ Pkg. develop (PackageSpec (path= full_repo_path))
5654
5755 @testset " benchmarkconfig" begin
5856 PkgBenchmark. _withtemp (tempname ()) do f
5957 str = """
6058 using BenchmarkTools
61- using Base. Test
59+ using Test
6260 SUITE = BenchmarkGroup()
6361 SUITE["foo"] = @benchmarkable 1+1
6462
@@ -70,14 +68,16 @@ temp_pkg_dir(;tmp_dir = tmp_dir) do
7068 end
7169
7270 config = BenchmarkConfig (juliacmd = ` $(joinpath (Sys. BINDIR, Base. julia_exename ())) -O3` ,
73- env = Dict (" JL_PKGBENCHMARK_TEST_ENV" => 10 ))
71+ env = Dict (" JL_PKGBENCHMARK_TEST_ENV" => 10 ))
7472 @test typeof (benchmarkpkg (TEST_PACKAGE_NAME, config, script= f; custom_loadpath= old_pkgdir)) == BenchmarkResults
75- end
7673 end
74+ end
7775
7876 # Make a commit with a small benchmarks.jl file
7977 testpkg_path = Pkg. dir (TEST_PACKAGE_NAME)
78+ LibGit2. init (testpkg_path)
8079 repo = LibGit2. GitRepo (testpkg_path)
80+ initial_commit = LibGit2. commit (repo, " Initial Commit" ; author= test_sig, committer= test_sig)
8181 LibGit2. branch! (repo, " master" )
8282
8383
@@ -117,7 +117,6 @@ temp_pkg_dir(;tmp_dir = tmp_dir) do
117117
118118 # Benchmark dirty repo
119119 cp (joinpath (@__DIR__ , " .." , " benchmark" , " benchmarks.jl" ), joinpath (testpkg_path, " benchmark" , " benchmarks.jl" ); force= true )
120- cp (joinpath (@__DIR__ , " .." , " benchmark" , " REQUIRE" ), joinpath (testpkg_path, " benchmark" , " REQUIRE" ))
121120 LibGit2. add! (repo, " benchmark/benchmarks.jl" )
122121 LibGit2. add! (repo, " benchmark/REQUIRE" )
123122 @test LibGit2. isdirty (repo)
0 commit comments