From 0cc83cd5ec230a67ed5375f14df25a39dddc6e1f Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 29 Jun 2020 16:43:45 -0400 Subject: [PATCH 1/2] Simplify runtime imports in test code Also use `BAIL_OUT` instead of `die` if `require 'ddclient'` fails. --- CONTRIBUTING.md | 6 ++++-- t/version.pl.in | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 569863d..0b94656 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -61,7 +61,9 @@ To add a new test script: ```perl use Test::More; - eval { require 'ddclient'; ddclient->import(); 1; } or die($@); + # Your test dependencies go here. + + eval { require 'ddclient'; } or BAIL_OUT($@); # Your tests go here. @@ -81,7 +83,7 @@ To add a new test script: module is not available. For example: ```perl - eval { require Foo::Bar; Foo::Bar->import(); 1 } or plan(skip_all => $@); + eval { require Foo::Bar; } or plan(skip_all => $@); ``` ## Compatibility diff --git a/t/version.pl.in b/t/version.pl.in index e3ad892..095486f 100644 --- a/t/version.pl.in +++ b/t/version.pl.in @@ -1,7 +1,7 @@ use Test::More; use version; -eval { require 'ddclient'; ddclient->import(); 1; } or die($@); +eval { require 'ddclient'; } or BAIL_OUT($@); is(ddclient->VERSION(), version->parse('v@PACKAGE_VERSION@'), "version matches Autoconf config"); From a8212a397e8d2e377fdd6004e4925fada86837df Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 29 Jun 2020 16:46:02 -0400 Subject: [PATCH 2/2] Add a test for unexpected warnings --- .github/workflows/ci.yml | 4 ++++ CONTRIBUTING.md | 1 + configure.ac | 4 +++- t/version.pl.in | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 952f34b..143a712 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: install test dependencies + run: sudo apt-get install libtest-warnings-perl - name: autogen run: ./autogen - name: configure @@ -24,6 +26,8 @@ jobs: runs-on: ubuntu-16.04 steps: - uses: actions/checkout@v2 + - name: install test dependencies + run: sudo apt-get install libtest-warnings-perl - name: autogen run: ./autogen - name: configure diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0b94656..7418506 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -63,6 +63,7 @@ To add a new test script: use Test::More; # Your test dependencies go here. + SKIP: { eval { require Test::Warnings; } or skip($@, 1); } eval { require 'ddclient'; } or BAIL_OUT($@); # Your tests go here. diff --git a/configure.ac b/configure.ac index b979141..30e8019 100644 --- a/configure.ac +++ b/configure.ac @@ -27,8 +27,10 @@ m4_foreach_w([_m], [ ], [AX_PROG_PERL_MODULES([_m], [], [AC_MSG_ERROR([missing required Perl module _m])])]) -# Perl modules required for tests. Only prints a warning. +# Perl modules required for tests. Only prints a warning if not +# installed. m4_foreach_w([_m], [ + Test::Warnings ], [AX_PROG_PERL_MODULES([_m], [], [AC_MSG_WARN([some tests may be skipped due to missing module _m])])]) diff --git a/t/version.pl.in b/t/version.pl.in index 095486f..42b1bb0 100644 --- a/t/version.pl.in +++ b/t/version.pl.in @@ -1,6 +1,7 @@ use Test::More; use version; +SKIP: { eval { require Test::Warnings; } or skip($@, 1); } eval { require 'ddclient'; } or BAIL_OUT($@); is(ddclient->VERSION(), version->parse('v@PACKAGE_VERSION@'), "version matches Autoconf config");