diff --git a/.github/workflows/perl-lint-checks.yml b/.github/workflows/perl-lint-checks.yml new file mode 100644 index 0000000..324c885 --- /dev/null +++ b/.github/workflows/perl-lint-checks.yml @@ -0,0 +1,26 @@ +--- +name: 'Perl static checks' + +on: + pull_request: + push: + branches: + - 'master' + +jobs: + perl-lint-checks: + runs-on: ubuntu-latest + name: "Perltidy" + container: + image: perldocker/perl-tester + steps: + - uses: actions/checkout@v4 + - run: GITHUB_ACTIONS=1 ./tools/tidyall --check-only --all --quiet + perl-critic-checks: + runs-on: ubuntu-latest + name: "Perlcritic" + container: + image: perldocker/perl-tester + steps: + - uses: actions/checkout@v4 + - run: ./tools/perlcritic --quiet . diff --git a/.github/workflows/perl-prove.yml b/.github/workflows/perl-prove.yml new file mode 100644 index 0000000..bd82966 --- /dev/null +++ b/.github/workflows/perl-prove.yml @@ -0,0 +1,18 @@ +--- +name: 'Perl tests' + +on: + pull_request: + push: + branches: + - 'master' + +jobs: + perl-prove: + runs-on: ubuntu-latest + name: "Prove" + container: + image: perldocker/perl-tester:5.26 + steps: + - uses: actions/checkout@v4 + - run: prove . diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7403810 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.tdy +.*.swp +*~ +__pycache__/ +.tidyall.d/ diff --git a/.perlcriticrc b/.perlcriticrc new file mode 100644 index 0000000..0addc1f --- /dev/null +++ b/.perlcriticrc @@ -0,0 +1,49 @@ +theme = community + openqa +severity = 4 +include = strict ValuesAndExpressions::ProhibitInterpolationOfLiterals + +verbose = ::warning file=%f,line=%l,col=%c,title=%m - severity %s::[%p] %e\n + +# == Perlcritic Policies +# -- Test::Most brings in strict & warnings +[TestingAndDebugging::RequireUseStrict] +equivalent_modules = Test::Most + +[TestingAndDebugging::RequireUseWarnings] +equivalent_modules = Test::Most + +# -- Avoid double quotes unless there's interpolation or a single quote. +[ValuesAndExpressions::ProhibitInterpolationOfLiterals] +allow_if_string_contains_single_quote = 1 +severity = 3 + +# -- Prohibit deep nesting +[ControlStructures::ProhibitDeepNests] +severity = 4 +add_themes = community +max_nests = 4 + +# == Community Policies +# -- Test::Most brings in strict & warnings +[Freenode::StrictWarnings] +extra_importers = Test::Most + +# -- Test::Most brings in strict & warnings +[Community::StrictWarnings] +extra_importers = Test::Most + +[Community::DiscouragedModules] +severity = 3 + +# Test modules have no package declaration +[Community::PackageMatchesFilename] +severity = 1 + +# == Custom Policies +# -- Useless quotes on hashes +[HashKeyQuotes] +severity = 5 + +# -- Superfluous use strict/warning. +[RedundantStrictWarning] +equivalent_modules = Test::Most diff --git a/.perltidyrc b/.perltidyrc new file mode 100644 index 0000000..60eb7ef --- /dev/null +++ b/.perltidyrc @@ -0,0 +1,14 @@ +# Workaround needed for handling non-ASCII in files. +# # See . +--character-encoding=none +--no-valign +-l=160 +-fbl # don't change blank lines +-fnl # don't remove new lines +-nsfs # no spaces before semicolons +-baao # space after operators +-bbao # space before operators +-pt=2 # no spaces around () +-bt=2 # no spaces around [] +-sbt=2 # no spaces around {} +-sct # stack closing tokens )} diff --git a/.proverc b/.proverc new file mode 100644 index 0000000..4c07390 --- /dev/null +++ b/.proverc @@ -0,0 +1,3 @@ +--formatter TAP::Formatter::File +--lib +xt/ diff --git a/.tidyallrc b/.tidyallrc new file mode 100644 index 0000000..d4c7a45 --- /dev/null +++ b/.tidyallrc @@ -0,0 +1,3 @@ +[PerlTidy] +select = **/*.{pl,pm,t} tools/tidyall tools/perlcritic tools/update-deps +argv = --profile=$ROOT/.perltidyrc diff --git a/README.md b/README.md index 537ea4b..ec95bdf 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,67 @@ # Common files for os-autoinst/os-autoinst and os-autoinst/openQA -This repository is to be used as a -[git-subrepo](https://github.com/ingydotnet/git-subrepo). +This repository is to be used as a [git-subrepo] +(https://github.com/ingydotnet/git-subrepo). See the instructions below in the +[Git Subrepo Usage](#git-subrepo-usage) section +All dependencies in this project are sourced from what's available in openSUSE +Tumbleweed RPM repositories. + +For developers not using RPM the tumbleweed repositories, a `cpanfile` is +provided and maintained in a best-effort basis. + +## Tooling offered + +This repo offers: + +* Static check configuration for perl projects: `.perltidyrc`, `.perlcriticrc`, + `.proverc` & `.tidyallrc`. +* Perlcritic policies that `os-autoinst/os-autoinst` and `os-autoinst/openQA` + share. +* Useful tools for linting & testing: + * A `perlcritic` wrapper that will automatically add Perlcritic rules + defined under `lib/perlcritic` and + `ext/os-autoinst-common/lib/perlcritic`. + * A `tidyall` wrapper that will validate the Perltidy version against the + `cpanfile` definition. + Because `Perl::Tidy` defaults may vary between versions this tool ensures + the version of perltidy matches the required version specified in the + `cpanfile` for non-`cpanm` based installs. + +* Example Github Actions for linting and unit testing for Perl. + +All files can be either copied or symlinked for any downstream repository +consuming these tools. + +## Running tools and tests from scratch + +```bash +# Run a container with the project mounted in it. +podman run -it -v "$PWD:/host/project" --workdir /host/project opensuse/leap:latest bash + +# Inside the container +zypper in -y perl-App-cpanminus make gcc +cpanm --installdeps . --with-develop + +prove . +./tools/tidyall --check-only --all --quiet +./tools/perlcritic --quiet . +``` + +## Git Subrepo Usage `git-subrepo` is available in the following repositories: [![Packaging status](https://repology.org/badge/vertical-allrepos/git-subrepo.svg)](https://repology.org/project/git-subrepo/versions) -## Usage - ### Clone To use it in your repository, you would usually do something like this: - % cd your-repo - % git subrepo clone git@github.com:os-autoinst/os-autoinst-common.git ext/os-autoinst-common +```bash +cd your-repo +git subrepo clone git@github.com:os-autoinst/os-autoinst-common.git ext/os-autoinst-common +``` This will automatically create a commit with information on what command was used. @@ -27,12 +73,14 @@ The cloned repository files will be part of your actual repository, so anyone cloning this repo will have the files automatically without needing to use `git-subrepo` themselves. -`ext` is just a convention, you can clone it into any directory. +`external` is just a convention, you can clone it into any directory. It's also possible to clone a branch (or a specific tag or sha): - % git subrepo clone git@github.com:os-autoinst/os-autoinst-common.git \ - -b branchname ext/os-autoinst-common +```bash +git subrepo clone git@github.com:os-autoinst/os-autoinst-common.git \ + -b branchname ext/os-autoinst-common +``` After cloning, you should see a file `ext/os-autoinst-common/.gitrepo` with information about the cloned commit. @@ -41,28 +89,35 @@ information about the cloned commit. To get the latest changes, you can pull: - % git subrepo pull ext/os-autoinst-common +```bash +git subrepo pull ext/os-autoinst-common +``` If that doesn't work for whatever reason, you can also simply reclone it like that: - % git subrepo clone --force git@github.com:os-autoinst/os-autoinst-common.git ext/os-autoinst-common +```bash +git subrepo clone --force git@github.com:os-autoinst/os-autoinst-common.git \ + ext/os-autoinst-common +``` ### Making changes -If you make changes in the subrepo inside of your top repo, you can simply commit -them and then do: +If you make changes in the subrepo inside of your top repo, you can simply +commit them and then do: - % git subrepo push ext/os-autoinst-common +```bash +git subrepo push ext/os-autoinst-common +``` ## git-subrepo You can find more information here: + * [Repository and usage](https://github.com/ingydotnet/git-subrepo) * [A good comparison between subrepo, submodule and subtree](https://github.com/ingydotnet/git-subrepo/blob/master/Intro.pod) - ## License This project is licensed under the MIT license, see LICENSE file for details. diff --git a/cpanfile b/cpanfile new file mode 100644 index 0000000..39389e7 --- /dev/null +++ b/cpanfile @@ -0,0 +1,19 @@ +################################################## +# WARNING +# This file is autogenerated by tools/update-deps +# from dependencies.yaml +################################################## + +# Needed until preaction/Log-Any#105 is solved. +requires 'Storable', '>= 3.06'; + +feature 'cover' => sub { + requires 'Devel::Cover'; + requires 'Devel::Cover::Report::Codecov'; +}; +on 'develop' => sub { + requires 'Code::TidyAll'; + requires 'Perl::Critic'; + requires 'Perl::Critic::Community'; + requires 'Perl::Tidy', '== 20230912'; +}; diff --git a/dependencies.yaml b/dependencies.yaml new file mode 100644 index 0000000..2fccb0e --- /dev/null +++ b/dependencies.yaml @@ -0,0 +1,26 @@ +--- +# % is placeholder for section. +# e.g.: +# % => develop +# %_requires => develop_requires +targets: + # List all %_requires into a cpanfile + cpanfile: [main, develop, cover] + cpanfile-targets: + # save %_require into cpanfile section + develop: develop + cover: cover + +main_requires: + # Needed until preaction/Log-Any#105 is solved. + perl(Storable): '>= 3.06' + +develop_requires: + perl(Perl::Tidy): '== 20230912' + perl(Code::TidyAll): + perl(Perl::Critic): + perl(Perl::Critic::Community): + +cover_requires: + perl(Devel::Cover): + perl(Devel::Cover::Report::Codecov): diff --git a/lib/OpenQA/Test/PatchDeparse.pm b/lib/OpenQA/Test/PatchDeparse.pm index 429c27f..ee69f2f 100644 --- a/lib/OpenQA/Test/PatchDeparse.pm +++ b/lib/OpenQA/Test/PatchDeparse.pm @@ -15,7 +15,8 @@ if ( ) { -#<<< do not let perltidy touch this +#<<< do not let perltidy nor perlcritic touch this +## no critic (TestingAndDebugging::ProhibitNoStrict ValuesAndExpressions::ProhibitInterpolationOfLiterals) # This is not our code, and formatting should stay the same for # better comparison with new versions of B::Deparse # <---- PATCH @@ -60,7 +61,7 @@ elsif ($B::Deparse::VERSION) { diag "Using B::Deparse v$B::Deparse::VERSION. If you see 'uninitialized' warnings, update patch in t/lib/OpenQA/Test/PatchDeparse.pm"; } - +## use critic 1; diff --git a/lib/OpenQA/Test/TimeLimit.pm b/lib/OpenQA/Test/TimeLimit.pm index 4aa3c5e..3f43182 100644 --- a/lib/OpenQA/Test/TimeLimit.pm +++ b/lib/OpenQA/Test/TimeLimit.pm @@ -1,25 +1,25 @@ -# Copyright 2020-2021 SUSE LLC +# Copyright SUSE LLC # SPDX-License-Identifier: GPL-2.0-or-later package OpenQA::Test::TimeLimit; use Test::Most; +use experimental 'signatures'; my $SCALE_FACTOR = $ENV{OPENQA_TEST_TIMEOUT_SCALE_FACTOR} // 1; -sub import { - my ($package, $limit) = @_; +sub import ($package, $limit = undef) { die "$package: Need argument on import, e.g. use: use OpenQA::Test::TimeLimit '42';" unless $limit; # disable timeout if requested by ENV variable or running within debugger return if ($ENV{OPENQA_TEST_TIMEOUT_DISABLE} or $INC{'perl5db.pl'}); $SCALE_FACTOR *= $ENV{OPENQA_TEST_TIMEOUT_SCALE_COVER} // 3 if Devel::Cover->can('report'); - $SCALE_FACTOR *= $ENV{OPENQA_TEST_TIMEOUT_SCALE_CI} // 2 if $ENV{CI}; - $limit *= $SCALE_FACTOR; + $SCALE_FACTOR *= $ENV{OPENQA_TEST_TIMEOUT_SCALE_CI} // 2 if $ENV{CI}; + $limit *= $SCALE_FACTOR; $SIG{ALRM} = sub { BAIL_OUT "test '$0' exceeds runtime limit of '$limit' seconds\n" }; alarm $limit; } -sub scale_timeout { - return $_[0] * $SCALE_FACTOR; +sub scale_timeout ($time) { + return $time * $SCALE_FACTOR; } 1; diff --git a/lib/perlcritic/Perl/Critic/Policy/ArgumentInUseStrictWarnings.pm b/lib/perlcritic/Perl/Critic/Policy/ArgumentInUseStrictWarnings.pm new file mode 100644 index 0000000..4c24edb --- /dev/null +++ b/lib/perlcritic/Perl/Critic/Policy/ArgumentInUseStrictWarnings.pm @@ -0,0 +1,42 @@ +# Copyright SUSE LLC +# SPDX-License-Identifier: GPL-2.0-or-later + +package Perl::Critic::Policy::ArgumentInUseStrictWarnings; + +use strict; +use warnings; +use experimental 'signatures'; +use base 'Perl::Critic::Policy'; + +use Perl::Critic::Utils qw( :severities :classification :ppi ); + +our $VERSION = '0.0.1'; + +sub default_severity { return $SEVERITY_HIGH } +sub default_themes { return qw(openqa) } +sub applies_to { return qw(PPI::Statement::Include) } + +my $desc = q{use strict/warnings with arguments}; +my $expl = q{Remove argument from: %s.}; + +# check that use use strict and warnings don't have arguments. +sub violates ($self, $elem, $document) { + # skip if it's not a use + return unless $elem->type() eq 'use'; + # skip if it's not a pragma + return unless my $pragma = $elem->pragma(); + # skip if it's not warnings or strict + return unless ($pragma eq 'warnings' || $pragma eq 'strict'); + + my @args = $elem->arguments(); + # skip if it doesn't have arguments + return if scalar(@args) == 0; + + # allow promoting warnings to FATAL + return if scalar(grep { $_->content eq 'FATAL' } @args); + + # Report the problem. + return $self->violation($desc, sprintf($expl, $elem), $elem); +} + +1; diff --git a/lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm b/lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm new file mode 100644 index 0000000..d71f441 --- /dev/null +++ b/lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm @@ -0,0 +1,34 @@ +# Copyright SUSE LLC +# SPDX-License-Identifier: GPL-2.0-or-later + +package Perl::Critic::Policy::HashKeyQuotes; + +use strict; +use warnings; +use experimental 'signatures'; +use base 'Perl::Critic::Policy'; + +use Perl::Critic::Utils qw( :severities :classification :ppi ); + +our $VERSION = '0.0.1'; + +sub default_severity { return $SEVERITY_HIGH } +sub default_themes { return qw(openqa) } +sub applies_to { return qw(PPI::Token::Quote::Single PPI::Token::Quote::Double) } + +# check that hashes are not overly using quotes +# (os-autoinst coding style) +sub violates ($self, $elem, $document) { + #we only want the check hash keys + return if !is_hash_key($elem); + + my $c = $elem->content; + # special characters + return if $c =~ m/[- \/<>.=_:\\\$\|]/; + + my $desc = q{Hash key with quotes}; + my $expl = q{Avoid useless quotes}; + return $self->violation($desc, $expl, $elem); +} + +1; diff --git a/lib/perlcritic/Perl/Critic/Policy/RedundantStrictWarning.pm b/lib/perlcritic/Perl/Critic/Policy/RedundantStrictWarning.pm new file mode 100644 index 0000000..80c099b --- /dev/null +++ b/lib/perlcritic/Perl/Critic/Policy/RedundantStrictWarning.pm @@ -0,0 +1,60 @@ +# Copyright SUSE LLC +# SPDX-License-Identifier: GPL-2.0-or-later + +package Perl::Critic::Policy::RedundantStrictWarning; + +use strict; +use warnings; +use version 0.77; +use experimental 'signatures'; + +use base 'Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict'; +use Perl::Critic::Utils qw{ $EMPTY }; +use Perl::Critic::Utils::Constants qw{ :equivalent_modules }; + +our $VERSION = '0.0.1'; +my $policy_title = q{Superfluoux use of strict/warning}; +my $policy_explanation = q{%s is equivalent to 'use strict; use warnings;'}; + +sub default_themes { return qw(openqa) } + +sub supported_parameters { + return ( + { + name => 'equivalent_modules', + description => + q, + default_string => $EMPTY, + behavior => 'string list', + list_always_present_values => ['warnings', 'strict', @STRICT_EQUIVALENT_MODULES], + }, + ); +} + +# check that use strict/warnings is not present when equivalent modules are. +sub violates ($self, $, $doc) { + # Find all equivalents of use strict/warnings. + my $stmnts_ref = $doc->find($self->_generate_is_use_strict()); + + # Bail if there's none. + return unless $stmnts_ref; + + # Bail out if there's only one. TestingAndDebugging::RequireUseStrict will report + # that there's no use strict/warnings. + return if scalar @{$stmnts_ref} == 1; + + # If the 'use strict' or 'use warnings' statement is present as well as a + # module already providing that behavior, -> it violates. + + my @viols; + + for my $stmnt (@{$stmnts_ref}) { + # skip pragmas + next if $stmnt->pragma(); + # Report the equivalent module. + push @viols, $self->violation($policy_title, sprintf($policy_explanation, $stmnt), $stmnt); + } + return @viols; +} + +1; diff --git a/tools/perlcritic b/tools/perlcritic new file mode 100755 index 0000000..8d2926a --- /dev/null +++ b/tools/perlcritic @@ -0,0 +1,24 @@ +#!/usr/bin/env perl +# Copyright SUSE LLC +# SPDX-License-Identifier: GPL-2.0-or-later +# +# perlcritic with auto-injection of custom perlcritic rules. +use strict; +use warnings; +use experimental 'signatures'; +use FindBin '$Bin'; + +sub extra_include_paths (@extra_paths) { + my @paths = (); + foreach my $path (@extra_paths) { + push @paths, "$Bin/../$path"; + push @paths, "$Bin/../external/os-autoinst-common/$path"; + } + + # Remove non existing paths + return grep { -e $_ } @paths; +} + +$ENV{PERL5LIB} = join(':', (extra_include_paths('lib/perlcritic'), $ENV{PERL5LIB} // '')); + +exec 'perlcritic', @ARGV; diff --git a/tools/tidyall b/tools/tidyall new file mode 100755 index 0000000..15e112d --- /dev/null +++ b/tools/tidyall @@ -0,0 +1,68 @@ +#!/usr/bin/env perl +# Copyright SUSE LLC +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Tidyall command with perltidy version constraint. +use strict; +use warnings; +use Perl::Tidy; +use Module::CPANfile; +use FindBin '$Bin'; + +=item perltidy_version() + +Grabs the perltidy version from cpanfile using Module::CPANfile. + +=cut + +sub perltidy_version() { + my $cpanfile_location; + # Try searching for a cpanfile in: + # - the current working directory + # - a directory above this command + # - the catch-all location in external/os-autoinst-common + my @locations = ('.', "$Bin/..", "$Bin/../external/os-autoinst-common"); + + foreach my $path (@locations) { + next unless -e "$path/cpanfile"; + $cpanfile_location = "$path/cpanfile" and last; + } + + my $version = Module::CPANfile->load($cpanfile_location) + ->prereq_for_module('Perl::Tidy') + ->requirement + ->version; + # Version requirements may contain qualifiers >=, ==, <, etc. The convention + # is to separate the qualifier from the actual version with a space. + # + # It's safe enough to assume that the last item is really the version. + return (split ' ', $version)[-1]; +} + +sub is_force_flag() { $_ eq '--force' } + +my $required_version = perltidy_version(); +my $detected_version = $Perl::Tidy::VERSION; +my @tidyall_argv = @ARGV; + +unless ($detected_version eq $required_version) { + print STDERR "Incorrect version of perltidy.\n"; + printf STDERR "- Detected: %s\n+ Required: %s\n\n", $detected_version, $required_version; + + my $force_run = grep { is_force_flag } @ARGV; + + unless ($force_run) { + printf STDERR "Please install the appropriate version of perltidy.\n"; + printf STDERR "If you want to proceed anyways, re run with --force flag.\n"; + exit 1; + } + + # tidyall does not know about the --force flag. + @tidyall_argv = grep { !is_force_flag } @tidyall_argv; + + print STDERR 'Proceeding to run with incorrect version of perltidy. '; + print STDERR "Results might not be consistent.\n"; + print STDERR "==================\n"; +} + +exec 'tidyall', @tidyall_argv; diff --git a/tools/update-deps b/tools/update-deps index 85b5465..6b39169 100755 --- a/tools/update-deps +++ b/tools/update-deps @@ -1,8 +1,10 @@ #!/usr/bin/env perl -# Copyright 2020 SUSE LLC -# SPDX-License-Identifier: MIT +# Copyright SUSE LLC +# SPDX-License-Identifier: GPL-2.0-or-later + use strict; use warnings; +use experimental 'signatures'; use 5.010; use YAML::PP; @@ -12,16 +14,16 @@ use Getopt::Long; use FindBin qw($Bin); GetOptions( - "help|h" => \my $help, - "specfile=s" => \my $specfile, - "dockerfile=s" => \my $dockerfile, + 'help|h' => \my $help, + 'specfile=s' => \my $specfile, + 'dockerfile=s' => \my $dockerfile, ); usage(0) if $help; usage(1) unless $specfile; my $scriptname = path(__FILE__)->to_rel("$Bin/.."); -my $yamlfile = "dependencies.yaml"; +my $yamlfile = 'dependencies.yaml'; my $file = "$Bin/../$yamlfile"; my $cpanfile = "$Bin/../cpanfile"; @@ -39,8 +41,7 @@ update_spec(); update_cpanfile($modules_by_target); update_dockerfile($dockerfile) if $dockerfile; -sub update_dockerfile { - my ($dockerfile) = @_; +sub update_dockerfile ($dockerfile) { my $docker = path($dockerfile)->slurp; my @perl; my @pkg; @@ -81,7 +82,7 @@ EOM say "Updated $dockerfile"; } -sub update_spec { +sub update_spec() { for my $target (@$spectargets) { my $name = $target . '_requires'; @@ -115,9 +116,7 @@ sub update_spec { say "Updated $specfile"; } -sub get_modules { - my ($data, $cpantargets, $cpantarget_mapping) = @_; - +sub get_modules ($data, $cpantargets, $cpantarget_mapping) { my %modules_by_target; for my $target (@$cpantargets) { my $name = $target . '_requires'; @@ -136,18 +135,17 @@ sub get_modules { return \%modules_by_target; } -sub _requires_line { +sub _requires_line ($modules, $module) { + # Generates the following: # requires 'Archive::Extract', '> 0.7'; - my ($hash, $module) = @_; - my $version = $hash->{$module}; + my $version = $modules->{$module}; my $line = "requires '$module'"; $line .= qq{, '$version'} if $version; $line .= ";\n"; return $line; } -sub update_cpanfile { - my ($modules_by_target) = @_; +sub update_cpanfile ($modules_by_target) { my $cpan = <<"EOM"; ################################################## # WARNING @@ -190,8 +188,7 @@ EOM say "Updated $cpanfile"; } -sub usage { - my ($exit) = @_; +sub usage ($exit) { print <<"EOM"; Usage: # update cpanfile and dist/rpm/os-autoinst.spec diff --git a/xt/01-make-update-deps.t b/xt/01-make-update-deps.t deleted file mode 100755 index 2d40642..0000000 --- a/xt/01-make-update-deps.t +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env perl -# Copyright 2022 SUSE LLC -# SPDX-License-Identifier: GPL-2.0-or-later - -use Test::Most; -use Test::Warnings; -use FindBin '$Bin'; - -if (not -e "$Bin/../.git") { - pass("Skipping all tests, not in a git repository"); - done_testing; - exit; -} - -my $build_dir = $ENV{OS_AUTOINST_BUILD_DIRECTORY} || "$Bin/.."; -my $make_tool = $ENV{OS_AUTOINST_MAKE_TOOL} || 'make'; -my $make_cmd = "$make_tool update-deps"; - -chdir $build_dir; -my @out = qx{$make_cmd}; -my $rc = $?; -die "Could not run $make_cmd: rc=$rc, out: @out" if $rc; - -my @status = grep { not m/^\?/ } qx{git -C "$Bin/.." status --porcelain}; -ok(!@status, "No changed files after '$make_cmd'") or diag @status; - -done_testing; - diff --git a/xt/02-use-timelimit.t b/xt/02-use-timelimit.t new file mode 100644 index 0000000..d3d62b0 --- /dev/null +++ b/xt/02-use-timelimit.t @@ -0,0 +1,18 @@ +#!/usr/bin/env perl +# Copyright SUSE LLC +# SPDX-License-Identifier: GPL-2.0-or-later + +use Test::Most; +use Test::Exception; + +throws_ok { + require OpenQA::Test::TimeLimit; + import OpenQA::Test::TimeLimit; +} qr/OpenQA::Test::TimeLimit: Need argument on import/, 'use without parameters is not allowed'; + +lives_ok { + require OpenQA::Test::TimeLimit; + import OpenQA::Test::TimeLimit 10; +} 'use with parameters is ok'; + +done_testing();