Skip to content

Commit

Permalink
Create fake data and use it on the tests
Browse files Browse the repository at this point in the history
Create a debug folder with a Debug module and a
Data module. The Data module includes fake data
for a variety of situations. This data is used
in the tests now.

Closes #375
  • Loading branch information
abelsiqueira committed Jul 25, 2024
1 parent 9d9d8bd commit b1114d0
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 53 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.9.1"
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/95-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ Pages = ["95-reference.md"]
```

```@autodocs
Modules = [BestieTemplate, BestieTemplate.Copier]
Modules = [BestieTemplate, BestieTemplate.Copier, BestieTemplate.Debug, BestieTemplate.Debug.Data]
```
1 change: 1 addition & 0 deletions src/BestieTemplate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ using YAML: YAML

include("Copier.jl")
include("api.jl")
include("debug/Debug.jl")
include("guess.jl")

end
52 changes: 52 additions & 0 deletions src/debug/Data.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
Fake data for testing
- `Debug.Data`: NamedTuple of Dictionaries with default data
- `Debug.Data.minimum_defaults`: Required data if you use `defaults = true`
- `Debug.Data.strategy_minimum`: Required data for strategy minimum, no defaults.
- `Debug.Data.strategy_recommended`: Required data for strategy recommended, no defaults.
- `Debug.Data.strategy_ask`: Required data for strategy ask, no defaults.
"""
module Data

using Random: MersenneTwister
using UUIDs: uuid4

const minimum_defaults = Dict(
"PackageName" => "FakePkg",
"PackageUUID" => string(uuid4(MersenneTwister(123))),
"PackageOwner" => "bestietemplate",
"AuthorName" => "Bestie Template",
"AuthorEmail" => "[email protected]",
)

const strategy_minimum = merge(
minimum_defaults,
Dict(
"JuliaMinVersion" => "1.6",
"License" => "MIT",
"Indentation" => "2",
"AnswerStrategy" => "minimum",
),
)

const strategy_recommended = merge(strategy_minimum, Dict("AnswerStrategy" => "recommended"))

const strategy_ask = merge(
strategy_recommended,
Dict(
"AnswerStrategy" => "ask",
"AddPrecommit" => true,
"AddMacToCI" => true,
"AddWinToCI" => true,
"RunJuliaNightlyOnCI" => true,
"UseCirrusCI" => false,
"AddCopierCI" => false,
"AddContributionDocs" => true,
"AddAllcontributors" => true,
"AddCodeOfConduct" => true,
"AddGitHubTemplates" => true,
),
)

end
12 changes: 12 additions & 0 deletions src/debug/Debug.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
Module Debug
Tools for debugging Bestie. Nothing here is public API.
Noteworthy: [`BestieTemplate.Debug.Data`](@ref)
"""
module Debug

include("Data.jl")

end
78 changes: 26 additions & 52 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,12 @@ if get(ENV, "CI", "nothing") == "nothing"
end

using BestieTemplate
using BestieTemplate.Debug.Data: Data
using Pkg
using PythonCall
using Test
using YAML

template_minimum_options = Dict(
"PackageName" => "Tmp",
"PackageUUID" => "1234",
"PackageOwner" => "test",
"AuthorName" => "Test",
"AuthorEmail" => "[email protected]",
)

template_options = Dict(
"PackageName" => "Tmp",
"PackageUUID" => "1234",
"PackageOwner" => "test",
"AuthorName" => "Test",
"AuthorEmail" => "[email protected]",
"AskAdvancedQuestions" => true,
"AddAllcontributors" => true,
"JuliaMinVersion" => "1.6",
"License" => "MIT",
"AddCodeOfConduct" => true,
"Indentation" => "3",
"AddMacToCI" => true,
"AddWinToCI" => true,
"RunJuliaNightlyOnCI" => true,
"AddContributionDocs" => true,
"UseCirrusCI" => false,
"AddPrecommit" => true,
"AddGitHubTemplates" => true,
"AnswerStrategy" => "ask",
"AddCopierCI" => false,
)

function _git_setup()
run(`git init`)
run(`git add .`)
Expand Down Expand Up @@ -82,8 +52,10 @@ function test_diff_dir(dir1, dir2)
end
end

min_bash_args = vcat([["-d"; "$k=$v"] for (k, v) in template_minimum_options]...)
bash_args = vcat([["-d"; "$k=$v"] for (k, v) in template_options]...)
data_to_cli_args(dict) = vcat([["-d"; "$k=$v"] for (k, v) in dict]...)
cli_args_min_defaults = data_to_cli_args(Data.minimum_defaults)
cli_args_strat_ask = data_to_cli_args(Data.strategy_ask)

template_path = joinpath(@__DIR__, "..")
template_url = "https://github.com/abelsiqueira/BestieTemplate.jl"

Expand All @@ -94,24 +66,24 @@ end

@testset "Compare BestieTemplate.generate vs copier CLI on URL/main" begin
mktempdir(TMPDIR; prefix = "cli_") do dir_copier_cli
run(`copier copy --vcs-ref main --quiet $bash_args $template_url $dir_copier_cli`)
run(`copier copy --vcs-ref main --quiet $cli_args_strat_ask $template_url $dir_copier_cli`)

mktempdir(TMPDIR; prefix = "copy_") do tmpdir
BestieTemplate.generate(tmpdir, template_options; quiet = true, vcs_ref = "main")
BestieTemplate.generate(tmpdir, Data.strategy_ask; quiet = true, vcs_ref = "main")
test_diff_dir(tmpdir, dir_copier_cli)
end
end
end

@testset "Compare BestieTemplate.generate vs copier CLI on HEAD" begin
mktempdir(TMPDIR; prefix = "cli_") do dir_copier_cli
run(`copier copy --vcs-ref HEAD --quiet $bash_args $template_path $dir_copier_cli`)
run(`copier copy --vcs-ref HEAD --quiet $cli_args_strat_ask $template_path $dir_copier_cli`)

mktempdir(TMPDIR; prefix = "copy_") do tmpdir
BestieTemplate.generate(
template_path,
tmpdir,
template_options;
Data.strategy_ask;
quiet = true,
vcs_ref = "HEAD",
)
Expand All @@ -122,17 +94,17 @@ end

@testset "Compare BestieTemplate.update vs copier CLI update" begin
mktempdir(TMPDIR; prefix = "cli_") do dir_copier_cli
run(`copier copy --defaults --quiet $min_bash_args $template_url $dir_copier_cli`)
run(`copier copy --defaults --quiet $cli_args_min_defaults $template_url $dir_copier_cli`)
cd(dir_copier_cli) do
_git_setup()
end
run(`copier update --defaults --quiet $bash_args $dir_copier_cli`)
run(`copier update --defaults --quiet $cli_args_strat_ask $dir_copier_cli`)

mktempdir(TMPDIR; prefix = "update_") do tmpdir
BestieTemplate.generate(tmpdir, template_minimum_options; defaults = true, quiet = true)
BestieTemplate.generate(tmpdir, Data.minimum_defaults; defaults = true, quiet = true)
cd(tmpdir) do
_git_setup()
BestieTemplate.update(template_options; defaults = true, quiet = true)
BestieTemplate.update(Data.strategy_ask; defaults = true, quiet = true)
end

test_diff_dir(tmpdir, dir_copier_cli)
Expand All @@ -142,7 +114,7 @@ end

@testset "Test that BestieTemplate.generate warns and exits for existing copy" begin
mktempdir(TMPDIR; prefix = "cli_") do dir_copier_cli
run(`copier copy --vcs-ref HEAD --quiet $bash_args $template_url $dir_copier_cli`)
run(`copier copy --vcs-ref HEAD --quiet $cli_args_strat_ask $template_url $dir_copier_cli`)
cd(dir_copier_cli) do
_git_setup()
end
Expand All @@ -169,7 +141,7 @@ end
BestieTemplate.generate(
template_path,
".",
template_options;
Data.strategy_ask;
quiet = true,
vcs_ref = "HEAD",
)
Expand All @@ -182,7 +154,7 @@ end
BestieTemplate.generate(
template_path,
"some_folder3",
template_options;
Data.strategy_ask;
quiet = true,
vcs_ref = "HEAD",
)
Expand All @@ -193,21 +165,23 @@ end

@testset "Testing copy, recopy and rebase" begin
mktempdir(TMPDIR; prefix = "cli_") do dir_copier_cli
run(`copier copy --vcs-ref HEAD --quiet $bash_args $template_path $dir_copier_cli`)
run(`copier copy --vcs-ref HEAD --quiet $cli_args_strat_ask $template_path $dir_copier_cli`)

@testset "Compare copied project vs copier CLI baseline" begin
mktempdir(TMPDIR; prefix = "copy_") do tmpdir
BestieTemplate.Copier.copy(tmpdir, template_options; quiet = true, vcs_ref = "HEAD")
BestieTemplate.Copier.copy(tmpdir, Data.strategy_ask; quiet = true, vcs_ref = "HEAD")
test_diff_dir(tmpdir, dir_copier_cli)
end
end

@testset "Compare recopied project vs copier CLI baseline" begin
mktempdir(TMPDIR; prefix = "recopy_") do tmpdir
run(`copier copy --vcs-ref HEAD --defaults --quiet $min_bash_args $template_path $tmpdir`)
run(
`copier copy --vcs-ref HEAD --defaults --quiet $cli_args_min_defaults $template_path $tmpdir`,
)
BestieTemplate.Copier.recopy(
tmpdir,
template_options;
Data.strategy_ask;
quiet = true,
overwrite = true,
vcs_ref = "HEAD",
Expand All @@ -218,7 +192,7 @@ end

@testset "Compare updated project vs copier CLI baseline" begin
mktempdir(TMPDIR; prefix = "update_") do tmpdir
run(`copier copy --defaults --quiet $min_bash_args $template_path $tmpdir`)
run(`copier copy --defaults --quiet $cli_args_min_defaults $template_path $tmpdir`)
cd(tmpdir) do
run(`git init`)
run(`git add .`)
Expand All @@ -228,7 +202,7 @@ end
end
BestieTemplate.Copier.update(
tmpdir,
template_options;
Data.strategy_ask;
overwrite = true,
quiet = true,
vcs_ref = "HEAD",
Expand Down Expand Up @@ -265,7 +239,7 @@ end
@testset "Test automatic guessing the package name from the path" begin
mktempdir(TMPDIR; prefix = "path_is_dir_") do dir_path_is_dir
cd(dir_path_is_dir) do
data = Dict(key => value for (key, value) in template_options if key != "PackageName")
data = Dict(key => value for (key, value) in Data.strategy_ask if key != "PackageName")
mkdir("some_folder")
BestieTemplate.generate(
template_path,
Expand Down Expand Up @@ -293,7 +267,7 @@ end
mktempdir(TMPDIR; prefix = "valid_pkg_name_") do dir
cd(dir) do
for name in ["Bad.jl", "0Bad", "bad"]
data = copy(template_options)
data = copy(Data.strategy_ask)
data["PackageName"] = name
@test_throws PythonCall.Core.PyException BestieTemplate.generate(
template_path,
Expand Down

0 comments on commit b1114d0

Please sign in to comment.