-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add QA objects and first couple of META6 checks
- Loading branch information
Showing
6 changed files
with
297 additions
and
0 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
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,52 @@ | ||
#! /usr/bin/env false | ||
|
||
use v6.c; | ||
|
||
use Dist::Helper::QA::Checks::Meta; | ||
|
||
unit module Dist::Helper::QA; | ||
|
||
multi sub dist-qa ( | ||
IO::Path:D $path, | ||
*%checks, | ||
Bool:D :$skip-rest = False, | ||
--> Hash | ||
) is export { | ||
sub include-check( | ||
Str:D $name | ||
) { | ||
if (%checks{$name}:!exists) { | ||
return !$skip-rest; | ||
} | ||
|
||
return ?%checks{$name}; | ||
} | ||
|
||
my IO::Path $cwd = $*CWD; | ||
chdir $path; | ||
|
||
my %todo; | ||
|
||
if (include-check("meta")) { %todo<meta> = Dist::Helper::QA::Checks::Meta } | ||
|
||
my %results; | ||
|
||
for %todo.kv -> $scope, $check { | ||
%results{$scope} = %todo{$scope}.check; | ||
} | ||
|
||
chdir $cwd; | ||
|
||
%results; | ||
} | ||
|
||
multi sub dist-qa ( | ||
Str:D $path = ".", | ||
*%checks, | ||
Bool:D :$skip-rest = False, | ||
--> Hash | ||
) is export { | ||
dist-qa($path.IO, |%checks, :$skip-rest); | ||
} | ||
|
||
# vim: ft=perl6 noet |
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,14 @@ | ||
#! /usr/bin/env false | ||
|
||
use v6.c; | ||
|
||
class Dist::Helper::QA::Check | ||
{ | ||
method check ( | ||
--> Iterable | ||
) { | ||
* | ||
} | ||
} | ||
|
||
# vim: ft=perl6 noet |
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,156 @@ | ||
#! /usr/bin/env false | ||
|
||
use v6.c; | ||
|
||
use Dist::Helper::Meta; | ||
use Dist::Helper::QA::Check; | ||
use Dist::Helper::QA::Result; | ||
use PostCocoon::Url; | ||
|
||
class Dist::Helper::QA::Checks::Meta is Dist::Helper::QA::Check | ||
{ | ||
method check ( | ||
--> Iterable | ||
) { | ||
try { | ||
CATCH { | ||
default { | ||
return [ | ||
Dist::Helper::QA::Result.new( | ||
description => "Distribution contains a valid META6.json" | ||
).failure: "Failed parsing META6.json"; | ||
]; | ||
} | ||
} | ||
|
||
my %meta = get-meta; | ||
|
||
[ | ||
self!required-fields(%meta), | ||
self!recommended-fields(%meta), | ||
self!correct-value-types(%meta), | ||
self!semantic-version(%meta), | ||
self!unused-deps(%meta), | ||
self!dependency-version-adverbs(%meta), | ||
] | ||
} | ||
} | ||
|
||
method !correct-value-types ( | ||
%meta, | ||
--> Dist::Helper::QA::Result | ||
) { | ||
my Dist::Helper::QA::Result $result .= new( | ||
description => "META6.json uses the correct types for all used fields", | ||
); | ||
|
||
my %types = | ||
api => Str, | ||
auth => Str, | ||
authors => Array, | ||
build-depends => Hash, | ||
depends => Hash, | ||
description => Str, | ||
license => Str, # TODO: Check for valid license | ||
name => Str, | ||
perl => Str, | ||
provides => Hash, | ||
resources => Hash, | ||
source-url => "Url", | ||
tags => Array, | ||
test-depends => Hash, | ||
version => Str, | ||
; | ||
|
||
for %types.kv -> $field, $type { | ||
next unless %meta{$field}:exists; | ||
|
||
given $type { | ||
when "Url" { | ||
if (!is-valid-url(%meta{$field})) { | ||
$result.failure: "$field is of the wrong type, should be $type"; | ||
} | ||
} | ||
default { | ||
if (%meta{$field} !~~ $type) { | ||
$result.failure: "$field is of the wrong type, should be $type"; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
method !dependency-version-adverbs ( | ||
--> Dist::Helper::QA::Result | ||
) { | ||
… | ||
} | ||
|
||
method !recommended-fields ( | ||
%meta, | ||
--> Dist::Helper::QA::Result | ||
) { | ||
my @fields = < | ||
api | ||
auth | ||
authors | ||
resources | ||
source-url | ||
tags | ||
test-depends | ||
>; | ||
|
||
my Dist::Helper::QA::Result $result .= new( | ||
description => "META6.json contains all recommended fields", | ||
); | ||
|
||
for @fields -> $field { | ||
if (%meta{$field}:!exists) { | ||
$result.failure: "Missing recommended field $field"; | ||
} | ||
} | ||
|
||
$result; | ||
} | ||
|
||
method !required-fields ( | ||
%meta, | ||
--> Dist::Helper::QA::Result | ||
) { | ||
my @fields = < | ||
depends | ||
description | ||
license | ||
name | ||
perl | ||
provides | ||
version | ||
>; | ||
|
||
my Dist::Helper::QA::Result $result .= new( | ||
description => "META6.json contains all required fields", | ||
); | ||
|
||
for @fields -> $field { | ||
if (%meta{$field}:!exists) { | ||
$result.failure: "Missing required field $field"; | ||
} | ||
} | ||
|
||
$result; | ||
} | ||
|
||
method !semantic-version ( | ||
--> Dist::Helper::QA::Result | ||
) { | ||
… | ||
} | ||
|
||
method !unused-deps ( | ||
--> Dist::Helper::QA::Result | ||
) { | ||
… | ||
} | ||
} | ||
|
||
# vim: ft=perl6 noet |
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,32 @@ | ||
#! /usr/bin/env false | ||
|
||
use v6.c; | ||
|
||
class Dist::Helper::QA::Result | ||
{ | ||
has Bool $.passed = True; | ||
has Str $.description; | ||
has Str @.reasons; | ||
|
||
method failure ( | ||
Str:D $reason, | ||
--> Dist::Helper::QA::Result | ||
) { | ||
$!passed = False; | ||
@!reasons.push: $reason; | ||
|
||
self; | ||
} | ||
|
||
method Str | ||
{ | ||
my Str $check-box = $.passed | ||
?? "[x]" | ||
!! "[ ]" | ||
; | ||
|
||
"$check-box $.message"; | ||
} | ||
} | ||
|
||
# vim: ft=perl6 noet |
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,38 @@ | ||
#! /usr/bin/env perl6 | ||
|
||
use v6.c; | ||
|
||
use Test; | ||
use Dist::Helper::QA; | ||
use Dist::Helper::QA::Result; | ||
|
||
plan 2; | ||
|
||
subtest "Check empty directory" => { | ||
plan 5; | ||
|
||
my %qa = dist-qa("t/repos/empty"); | ||
|
||
ok %qa<meta>:exists, "meta key exists"; | ||
is %qa<meta>.elems, 1, "meta contains 1 element"; | ||
nok %qa<meta>[0].passed, "meta[0] did not pass"; | ||
is %qa<meta>[0].reasons.elems, 1, "meta[0] has 1 failure reason"; | ||
|
||
subtest "Types" => { | ||
plan 3; | ||
|
||
isa-ok %qa<meta>[0], Dist::Helper::QA::Result, "meta[0] is a Dist::Helper::QA::Result"; | ||
isa-ok %qa<meta>[0].description, Str, "meta[0].description is a Str"; | ||
isa-ok %qa<meta>[0].reasons[0], Str, "meta[0].reasons[0] is a Str"; | ||
} | ||
} | ||
|
||
subtest "Ignore checks" => { | ||
plan 1; | ||
|
||
my %qa = dist-qa("t/repos/empty", :!meta); | ||
|
||
ok %qa<meta>:!exists, "meta key does not exist"; | ||
} | ||
|
||
# vim: ft=perl6 noet |