From 205963bebccebbc5b4b04180a23a69443985ad62 Mon Sep 17 00:00:00 2001 From: Abel Soares Siqueira Date: Fri, 24 May 2024 11:43:32 +0200 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20Improve=20folder=20c?= =?UTF-8?q?omparison=20in=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #139 --- test/runtests.jl | 51 ++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 32f94cb4..0ab0b6f0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -26,31 +26,44 @@ template_options = Dict( "UseCirrusCI" => true, ) -@testset "Compare folder generated by this call vs direct copier" begin - tmpdir1 = mktempdir() - tmpdir2 = mktempdir() +function test_diff_dir(dir1, dir2) + ignore(line) = startswith("_commit")(line) || startswith("_src_path")(line) + @testset "$(basename(dir1)) vs $(basename(dir2))" begin + for (root, _, files) in walkdir(dir1) + nice_dir(file) = + replace(root, dir1 => "") |> out -> replace(out, r"^/" => "") |> out -> joinpath(out, file) + if nice_dir("") |> startswith(".git") + continue + end + @testset "File $(nice_dir(file))" for file in files + file1 = joinpath(root, file) + file2 = replace(file1, dir1 => dir2) + lines1 = readlines(file1) + lines2 = readlines(file2) + for (line1, line2) in zip(lines1, lines2) + ignore(line1) && continue + @test line1 == line2 + end + end + end + end +end +bash_args = vcat([["-d"; "$k=$v"] for (k, v) in template_options]...) +template_path = joinpath(@__DIR__, "..") + +@testset "Compare COPIERTemplate.generate vs copier CLI on HEAD" begin # This is a hack because Windows managed to dirty the repo. if get(ENV, "CI", "nothing") == "true" && Sys.iswindows() run(`git reset --hard HEAD`) end - COPIERTemplate.generate(tmpdir1; data = template_options, vcs_ref = "HEAD") - bash_args = vcat([["-d"; "$k=$v"] for (k, v) in template_options]...) - ignore(line) = startswith("_commit")(line) || startswith("_src_path")(line) - template_path = joinpath(@__DIR__, "..") - run(`copier copy --vcs-ref HEAD $bash_args $template_path $tmpdir2`) - for (root, dirs, files) in walkdir(tmpdir1) - for file in files - file1 = joinpath(root, file) - file2 = replace(file1, tmpdir1 => tmpdir2) - lines1 = readlines(file1) - lines2 = readlines(file2) - diff = [ - "$line1 vs $line2" for - (line1, line2) in zip(lines1, lines2) if !ignore(line1) && line1 != line2 - ] - @test diff == [] + mktempdir(; prefix = "cli_") do dir_copier_cli + run(`copier copy --vcs-ref HEAD --quiet $bash_args $template_path $dir_copier_cli`) + + mktempdir(; prefix = "copy_") do tmpdir + COPIERTemplate.generate(tmpdir; data = template_options, quiet = true, vcs_ref = "HEAD") + test_diff_dir(tmpdir, dir_copier_cli) end end end