From 3e13de0966e361ca4e70cfd2d781320f25d820d3 Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Wed, 27 Sep 2017 16:25:49 -0400 Subject: Bug 1402878 - Add some more sanity-type tests, including perl critic --- t/.perlcritic-history | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++ t/002goodperl.t | 12 +++-- t/critic.t | 17 ++++++ t/docker.t | 52 ++++++++++++++++++ 4 files changed, 223 insertions(+), 5 deletions(-) create mode 100644 t/.perlcritic-history create mode 100644 t/critic.t create mode 100644 t/docker.t (limited to 't') diff --git a/t/.perlcritic-history b/t/.perlcritic-history new file mode 100644 index 000000000..8d21a03b6 --- /dev/null +++ b/t/.perlcritic-history @@ -0,0 +1,147 @@ +$VAR1 = [ + { + 'Perl::Critic::Policy::ValuesAndExpressions::ProhibitNoisyQuotes' => 29, + 'Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage' => 0, + 'Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls' => 0, + 'Perl::Critic::Policy::BuiltinFunctions::ProhibitComplexMappings' => 0, + 'Perl::Critic::Policy::ControlStructures::ProhibitLabelsWithSpecialBlockNames' => 0, + 'Perl::Critic::Policy::CodeLayout::ProhibitTrailingWhitespace' => 0, + 'Perl::Critic::Policy::Variables::ProhibitUnusedVariables' => 0, + 'Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName' => 0, + 'Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalCan' => 0, + 'Perl::Critic::Policy::InputOutput::ProhibitJoinedReadline' => 0, + 'Perl::Critic::Policy::Variables::ProhibitReusedNames' => 7, + 'Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit' => 1, + 'Perl::Critic::Policy::Subroutines::ProhibitNestedSubs' => 0, + 'Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions' => 0, + 'Perl::Critic::Policy::Variables::ProhibitPerl4PackageNames' => 0, + 'Perl::Critic::Policy::ControlStructures::ProhibitYadaOperator' => 0, + 'Perl::Critic::Policy::Freenode::Each' => 0, + 'Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements' => 0, + 'Perl::Critic::Policy::Freenode::OpenArgs' => 2, + 'Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings' => 0, + 'Perl::Critic::Policy::Miscellanea::ProhibitTies' => 0, + 'Perl::Critic::Policy::Modules::ProhibitEvilModules' => 0, + 'Perl::Critic::Policy::Subroutines::ProhibitManyArgs' => 0, + 'Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators' => 0, + 'Perl::Critic::Policy::Freenode::POSIXImports' => 0, + 'Perl::Critic::Policy::Freenode::DollarAB' => 0, + 'Perl::Critic::Policy::ValuesAndExpressions::RequireQuotedHeredocTerminator' => 29, + 'Perl::Critic::Policy::InputOutput::ProhibitOneArgSelect' => 0, + 'Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation' => 16, + 'Perl::Critic::Policy::Freenode::ModPerl' => 0, + 'Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings' => 1, + 'Perl::Critic::Policy::Freenode::IndirectObjectNotation' => 0, + 'Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils' => 0, + 'Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode' => 0, + 'Perl::Critic::Policy::Subroutines::ProhibitSubroutinePrototypes' => 5, + 'Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap' => 0, + 'Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions' => 1, + 'Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval' => 3, + 'Perl::Critic::Policy::InputOutput::ProhibitBacktickOperators' => 0, + 'Perl::Critic::Policy::Variables::RequireLocalizedPunctuationVars' => 7, + 'Perl::Critic::Policy::CodeLayout::RequireConsistentNewlines' => 0, + 'Perl::Critic::Policy::Miscellanea::ProhibitUselessNoCritic' => 0, + 'Perl::Critic::Policy::TestingAndDebugging::ProhibitNoStrict' => 1, + 'Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval' => 1, + 'Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalIsa' => 0, + 'Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists' => 0, + 'Perl::Critic::Policy::NamingConventions::ProhibitAmbiguousNames' => 0, + 'Perl::Critic::Policy::Variables::ProhibitConditionalDeclarations' => 0, + 'Perl::Critic::Policy::InputOutput::ProhibitExplicitStdin' => 1, + 'Perl::Critic::Policy::ValuesAndExpressions::ProhibitInterpolationOfLiterals' => 272, + 'Perl::Critic::Policy::Freenode::Wantarray' => 0, + 'Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators' => 0, + 'Perl::Critic::Policy::InputOutput::RequireBracedFileHandleWithPrint' => 15, + 'Perl::Critic::Policy::CodeLayout::RequireTidyCode' => 50, + 'Perl::Critic::Policy::Subroutines::ProhibitBuiltinHomonyms' => 0, + 'Perl::Critic::Policy::Modules::RequireExplicitPackage' => 0, + 'Perl::Critic::Policy::CodeLayout::ProhibitHardTabs' => 0, + 'Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr' => 0, + 'Perl::Critic::Policy::Freenode::OverloadOptions' => 0, + 'Perl::Critic::Policy::TestingAndDebugging::ProhibitProlongedStrictureOverride' => 0, + 'Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros' => 0, + 'Perl::Critic::Policy::CodeLayout::RequireTrailingCommas' => 3, + 'Perl::Critic::Policy::Miscellanea::ProhibitUnrestrictedNoCritic' => 0, + 'Perl::Critic::Policy::BuiltinFunctions::ProhibitSleepViaSelect' => 0, + 'Perl::Critic::Policy::RegularExpressions::ProhibitEscapedMetacharacters' => 3, + 'Perl::Critic::Policy::NamingConventions::Capitalization' => 0, + 'Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish' => 1, + 'Perl::Critic::Policy::RegularExpressions::RequireLineBoundaryMatching' => 37, + 'Perl::Critic::Policy::InputOutput::RequireEncodingWithUTF8Layer' => 1, + 'Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidGrep' => 0, + 'Perl::Critic::Policy::ValuesAndExpressions::RequireUpperCaseHeredocTerminator' => 0, + 'Perl::Critic::Policy::Miscellanea::ProhibitFormats' => 0, + 'Perl::Critic::Policy::Variables::RequireInitializationForLocalVars' => 0, + 'Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins' => 83, + 'Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses' => 0, + 'Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements' => 0, + 'Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep' => 4, + 'Perl::Critic::Policy::Freenode::AmpersandSubCalls' => 0, + 'Perl::Critic::Policy::Modules::RequireEndWithOne' => 0, + 'Perl::Critic::Policy::InputOutput::ProhibitTwoArgOpen' => 2, + 'Perl::Critic::Policy::ValuesAndExpressions::RequireConstantVersion' => 0, + 'Perl::Critic::Policy::InputOutput::RequireCheckedSyscalls' => 168, + 'Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars' => 0, + 'Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict' => 0, + 'Perl::Critic::Policy::ControlStructures::ProhibitUntilBlocks' => 0, + 'Perl::Critic::Policy::Freenode::ArrayAssignAref' => 0, + 'Perl::Critic::Policy::Freenode::ConditionalDeclarations' => 0, + 'Perl::Critic::Policy::Objects::ProhibitIndirectSyntax' => 22, + 'Perl::Critic::Policy::BuiltinFunctions::RequireGlobFunction' => 0, + 'Perl::Critic::Policy::TestingAndDebugging::RequireTestLabels' => 0, + 'Perl::Critic::Policy::ClassHierarchies::ProhibitExplicitISA' => 0, + 'Perl::Critic::Policy::Modules::ProhibitExcessMainComplexity' => 6, + 'Perl::Critic::Policy::ValuesAndExpressions::ProhibitEscapedCharacters' => 1, + 'Perl::Critic::Policy::Freenode::WarningsSwitch' => 19, + 'Perl::Critic::Policy::RegularExpressions::ProhibitCaptureWithoutTest' => 0, + 'Perl::Critic::Policy::Variables::ProhibitPunctuationVars' => 14, + 'Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches' => 2, + 'Perl::Critic::Policy::ClassHierarchies::ProhibitOneArgBless' => 0, + 'Perl::Critic::Policy::BuiltinFunctions::RequireSimpleSortBlock' => 0, + 'Perl::Critic::Policy::InputOutput::RequireCheckedOpen' => 0, + 'Perl::Critic::Policy::RegularExpressions::ProhibitUnusualDelimiters' => 1, + 'Perl::Critic::Policy::RegularExpressions::ProhibitUselessTopic' => 0, + 'Perl::Critic::Policy::Variables::ProhibitAugmentedAssignmentInDeclaration' => 1, + 'Perl::Critic::Policy::ValuesAndExpressions::RequireNumberSeparators' => 1, + 'Perl::Critic::Policy::Freenode::DiscouragedModules' => 5, + 'Perl::Critic::Policy::Subroutines::ProtectPrivateSubs' => 1, + 'Perl::Critic::Policy::ValuesAndExpressions::ProhibitComplexVersion' => 0, + 'Perl::Critic::Policy::ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator' => 0, + 'Perl::Critic::Policy::Modules::ProhibitMultiplePackages' => 0, + 'Perl::Critic::Policy::Variables::ProhibitMatchVars' => 0, + 'Perl::Critic::Policy::Variables::RequireLexicalLoopIterators' => 0, + 'Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidMap' => 0, + 'Perl::Critic::Policy::ValuesAndExpressions::ProhibitImplicitNewlines' => 55, + 'Perl::Critic::Policy::Modules::RequireBarewordIncludes' => 0, + 'Perl::Critic::Policy::InputOutput::ProhibitBarewordFileHandles' => 2, + 'Perl::Critic::Policy::InputOutput::RequireCheckedClose' => 1, + 'Perl::Critic::Policy::ControlStructures::ProhibitDeepNests' => 0, + 'Perl::Critic::Policy::ControlStructures::ProhibitCStyleForLoops' => 2, + 'Perl::Critic::Policy::InputOutput::ProhibitReadlineInForLoop' => 0, + 'Perl::Critic::Policy::Freenode::WhileDiamondDefaultAssignment' => 0, + 'Perl::Critic::Policy::RegularExpressions::ProhibitUnusedCapture' => 0, + 'Perl::Critic::Policy::InputOutput::ProhibitInteractiveTest' => 1, + 'Perl::Critic::Policy::Modules::ProhibitAutomaticExportation' => 0, + 'Perl::Critic::Policy::RegularExpressions::RequireDotMatchAnything' => 38, + 'Perl::Critic::Policy::Subroutines::RequireArgUnpacking' => 2, + 'Perl::Critic::Policy::RegularExpressions::RequireBracesForMultiline' => 0, + 'Perl::Critic::Policy::Subroutines::ProhibitUnusedPrivateSubroutines' => 0, + 'Perl::Critic::Policy::Documentation::RequirePodAtEnd' => 4, + 'Perl::Critic::Policy::Freenode::StrictWarnings' => 0, + 'Perl::Critic::Policy::Variables::ProtectPrivateVars' => 0, + 'Perl::Critic::Policy::Freenode::DeprecatedFeatures' => 0, + 'Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep' => 6, + 'Perl::Critic::Policy::Freenode::Prototypes' => 5, + 'Perl::Critic::Policy::Freenode::ConditionalImplicitReturn' => 0, + 'Perl::Critic::Policy::BuiltinFunctions::ProhibitReverseSortBlock' => 0, + 'Perl::Critic::Policy::Freenode::EmptyReturn' => 0, + 'Perl::Critic::Policy::ClassHierarchies::ProhibitAutoloading' => 0, + 'Perl::Critic::Policy::Freenode::Threads' => 0, + 'Perl::Critic::Policy::Freenode::BarewordFilehandles' => 2, + 'Perl::Critic::Policy::Subroutines::ProhibitReturnSort' => 0, + 'Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters' => 0, + 'Perl::Critic::Policy::Variables::RequireNegativeIndices' => 0, + 'Perl::Critic::Policy::InputOutput::RequireBriefOpen' => 4 + } + ]; diff --git a/t/002goodperl.t b/t/002goodperl.t index d770b7b4f..5f201160b 100644 --- a/t/002goodperl.t +++ b/t/002goodperl.t @@ -54,6 +54,8 @@ foreach my $file (@testitems) { } elsif ($ext eq "cgi") { # cgi files must be taint checked $flags = 'T'; + } elsif ($ext eq 't') { + $flags = ''; } else { ok(0, "$file has shebang but unknown extension"); next; @@ -129,20 +131,20 @@ foreach my $file (@testitems) { } my $lineno = 0; my $error = 0; - + while (!$error && (my $file_line = )) { $lineno++; if ($file_line =~ /Throw.*Error\("(.*?)"/) { if ($1 =~ /\s/) { - ok(0,"$file has a Throw*Error call on line $lineno + ok(0,"$file has a Throw*Error call on line $lineno which doesn't use a tag --ERROR"); - $error = 1; + $error = 1; } } } - + ok(1,"$file uses Throw*Error calls correctly") if !$error; - + close(FILE); } diff --git a/t/critic.t b/t/critic.t new file mode 100644 index 000000000..6e37cc0df --- /dev/null +++ b/t/critic.t @@ -0,0 +1,17 @@ +#!/usr/bin/perl +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. +use 5.10.1; +use strict; +use warnings; +use lib qw(. lib local/lib/perl5); +use Test::More; + +my $ok = eval { require Test::Perl::Critic::Progressive }; +plan skip_all => 'T::P::C::Progressive required for this test' unless $ok; + +Test::Perl::Critic::Progressive::progressive_critic_ok(); \ No newline at end of file diff --git a/t/docker.t b/t/docker.t new file mode 100644 index 000000000..3c8cd055b --- /dev/null +++ b/t/docker.t @@ -0,0 +1,52 @@ +#!/usr/bin/perl +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. +use 5.10.1; +use strict; +use warnings; +use autodie; +use lib qw(. lib local/lib/perl5); +use IO::Handle; +use Test::More; + +my $dockerfile = 'Dockerfile'; +my $ci_config = '.circleci/config.yml'; + +my $base; +open my $dockerfile_fh, '<', $dockerfile; +while (my $line = readline $dockerfile_fh) { + chomp $line; + if ($line =~ /^FROM\s+(\S+)/ms) { + $base = $1; + last; + } +} +close $dockerfile_fh; + +my ($image, $version) = split(/:/ms, $base, 2); +is($image, 'mozillabteam/bmo-slim', "base image is mozillabteam/bmo-slim"); +like($version, qr/\d{4}\d{2}\d{2}\.\d+/ms, "version is YYYYMMDD.x"); + +my $regex = qr{ + \Q$image\E + : + (?!\Q$version\E) + (\d{4}\d{2}\d{2}\.\d+) +}msx; + +open my $ci_config_fh, '<', $ci_config; +while (my $line = readline $ci_config_fh) { + chomp $line; + if ($line =~ /($regex)/ms) { + my $ln = $ci_config_fh->input_line_number; + fail("found docker image $1, expected $base in $ci_config line $ln"); + } + pass("Forbidden version not found"); +} +close $ci_config_fh; + +done_testing; \ No newline at end of file -- cgit v1.2.3-24-g4f1b