-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test_project_toml_formatting (#34)
* Add test_project_toml_formatting * Optionally run test_project_toml_formatting via test_all
- Loading branch information
Showing
7 changed files
with
221 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
Aqua.test_project_toml_formatting(packages) | ||
""" | ||
function test_project_toml_formatting(packages) | ||
@testset "$(result.label)" for result in analyze_project_toml_formatting(packages) | ||
@debug result.label result | ||
@test result ⊜ true | ||
end | ||
end | ||
|
||
analyze_project_toml_formatting(packages) = | ||
[_analyze_project_toml_formatting_1(path) for path in project_toml_files_in(packages)] | ||
|
||
project_toml_files_in(path::AbstractString) = [path] | ||
project_toml_files_in(m::Module) = project_toml_files_in(PkgId(m)) | ||
function project_toml_files_in(pkg::PkgId) | ||
srcpath = Base.locate_package(pkg) | ||
if srcpath === nothing | ||
# TODO: record this as a test failure? | ||
error("Package file and directory not found: $pkg") | ||
end | ||
dir = dirname(dirname(srcpath)) | ||
paths = [project_toml_path(dir)[1]] | ||
p, found = project_toml_path(joinpath(dir, "test")) | ||
found && push!(paths, p) | ||
return paths | ||
end | ||
|
||
project_toml_files_in(iterable) = | ||
[path for x in iterable for path in project_toml_files_in(x)] | ||
|
||
function _analyze_project_toml_formatting_1(path::AbstractString) | ||
label = path | ||
|
||
if !isfile(path) | ||
return LazyTestResult(label, "Path `$path` is not an existing file.", false) | ||
end | ||
|
||
original = read(path, String) | ||
return _analyze_project_toml_formatting_2(path, original) | ||
end | ||
|
||
function _analyze_project_toml_formatting_2(path::AbstractString, original) | ||
@debug "Checking TOML style: `$path`" Text(original) | ||
label = path | ||
|
||
prj = TOML.parse(original) | ||
formatted = sprint(print_project, prj) | ||
if original == formatted | ||
LazyTestResult( | ||
label, | ||
"Running `Pkg.resolve` on `$(path)` did not change the content.", | ||
true, | ||
) | ||
else | ||
diff = format_diff( | ||
"Original $(basename(path))" => original, | ||
"Pkg's output" => formatted, | ||
) | ||
LazyTestResult( | ||
label, | ||
""" | ||
Running `Pkg.resolve` on `$(path)` will change the content. | ||
$diff | ||
""", | ||
false, | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
module TestProjectTomlFormatting | ||
|
||
using Aqua: _analyze_project_toml_formatting_2, ⊜ | ||
using Test | ||
|
||
@testset "_analyze_project_toml_formatting_2" begin | ||
path = "DUMMY/PATH" | ||
@testset "pass" begin | ||
@test _analyze_project_toml_formatting_2( | ||
path, | ||
""" | ||
[deps] | ||
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
""", | ||
) ⊜ true | ||
@test _analyze_project_toml_formatting_2( | ||
path, | ||
""" | ||
name = "Aqua" | ||
uuid = "4c88cf16-eb10-579e-8560-4a9242c79595" | ||
authors = ["Takafumi Arakaki <[email protected]>"] | ||
version = "0.4.7-DEV" | ||
[deps] | ||
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
[compat] | ||
julia = "1.0" | ||
[extras] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
[targets] | ||
test = ["Test"] | ||
""", | ||
) ⊜ true | ||
end | ||
@testset "failure: reversed deps" begin | ||
t = _analyze_project_toml_formatting_2( | ||
path, | ||
""" | ||
[deps] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" | ||
""", | ||
) | ||
@debug "failure: reversed deps" t | ||
@test t ⊜ false | ||
@test occursin("change the content", string(t)) | ||
end | ||
@testset "failure: reversed table" begin | ||
t = _analyze_project_toml_formatting_2( | ||
path, | ||
""" | ||
[compat] | ||
julia = "1.0" | ||
[deps] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" | ||
""", | ||
) | ||
@debug "failure: reversed table" t | ||
@test t ⊜ false | ||
@test occursin("change the content", string(t)) | ||
end | ||
end | ||
|
||
end # module |
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