-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from KristofferC/kc/tests
make a basic functional API and add some very basic tests
- Loading branch information
Showing
5 changed files
with
89 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module API | ||
|
||
import Pkg3 | ||
using Pkg3.Types | ||
using Base.Random.UUID | ||
|
||
add(pkg::String) = add([pkg]) | ||
add(pkgs::Vector{String}) = add([PackageSpec(pkg) for pkg in pkgs]) | ||
add(pkgs::Vector{PackageSpec}) = add(EnvCache(), pkgs) | ||
|
||
function add(env::EnvCache, pkgs::Vector{PackageSpec}) | ||
project_resolve!(env, pkgs) | ||
registry_resolve!(env, pkgs) | ||
ensure_resolved(env, pkgs, true) | ||
Pkg3.Operations.add(env, pkgs) | ||
end | ||
|
||
|
||
rm(pkg::String) = rm([pkg]) | ||
rm(pkgs::Vector{String}) = rm([PackageSpec(pkg) for pkg in pkgs]) | ||
rm(pkgs::Vector{PackageSpec}) = rm(EnvCache(), pkgs) | ||
|
||
function rm(env::EnvCache, pkgs::Vector{PackageSpec}) | ||
project_resolve!(env, pkgs) | ||
manifest_resolve!(env, pkgs) | ||
Pkg3.Operations.rm(env, pkgs) | ||
end | ||
|
||
|
||
up(;kwargs...) = up(PackageSpec[], kwargs...) | ||
up(pkg::String; kwargs...) = up([pkg]; kwargs...) | ||
up(pkgs::Vector{String}; kwargs...) = up([PackageSpec(pkg) for pkg in pkgs]; kwargs...) | ||
up(pkgs::Vector{PackageSpec}; kwargs...) = up(EnvCache(), pkgs; kwargs...) | ||
|
||
function up(env::EnvCache, pkgs::Vector{PackageSpec}; | ||
level::UpgradeLevel=UpgradeLevel(:major), mode::Symbol=:project) | ||
if isempty(pkgs) | ||
if mode == :project | ||
for (name::String, uuid::UUID) in env.project["deps"] | ||
push!(pkgs, PackageSpec(name, uuid, level)) | ||
end | ||
elseif mode == :manifest | ||
for (name, infos) in env.manifest, info in infos | ||
uuid = UUID(info["uuid"]) | ||
push!(pkgs, PackageSpec(name, uuid, level)) | ||
end | ||
end | ||
else | ||
project_resolve!(env, pkgs) | ||
manifest_resolve!(env, pkgs) | ||
ensure_resolved(env, pkgs) | ||
end | ||
Pkg3.Operations.up(env, pkgs) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,28 @@ | ||
using Pkg3 | ||
using Base.Test | ||
using Pkg3.Types | ||
|
||
function temp_pkg_dir(fn::Function) | ||
local project_path | ||
try | ||
project_path = joinpath(tempdir(), randstring()) | ||
withenv("JULIA_ENV" => project_path) do | ||
fn() | ||
end | ||
finally | ||
rm(project_path, recursive=true, force=true) | ||
end | ||
end | ||
|
||
temp_pkg_dir() do | ||
Pkg3.API.add("Example") | ||
@eval import Example | ||
Pkg3.API.up() | ||
Pkg3.API.rm("Example") | ||
|
||
nonexisting_pkg = randstring(14) | ||
@test_throws CommandError Pkg3.API.add(nonexisting_pkg) | ||
@test_throws CommandError Pkg3.API.up(nonexisting_pkg) | ||
@test_warn "not in project" Pkg3.API.rm(nonexisting_pkg) | ||
end | ||
|
||
# write your own tests here | ||
@test 1 == 2 |