From 65f695410e7b4dea2a451d04c37a9234edc300b6 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 12 Mar 2019 13:02:35 +0000 Subject: [PATCH] test compilation of all scripts and modules (#537) * test compilation of all scripts and modules passes * try adding NetSNMP::default_store * try adding NetSNMP::default_store * travis test all branches * make Configuration.pm safe for tests * remove dep * try adding net-snmp * dist: xenial * try building Net-SNMP locally * no need for Try::Tiny * allow test to pass for DPP:p * better testing setup for session cookies * yay! working compile tests for ALL! --- .travis.yml | 11 +++---- Build.PL | 1 + lib/App/Netdisco/Web.pm | 10 +++++-- lib/App/Netdisco/Worker/Plugin/DumpConfig.pm | 3 +- xt/00-compile.t | 30 ++++++++++++++++++++ 5 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 xt/00-compile.t diff --git a/.travis.yml b/.travis.yml index 31f15896..297e8260 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,11 +6,12 @@ addons: - phantomjs hosts: - localhost -#branches: -# only: -# - /^2\.\d{6}$/ -# - 'master' -install: true +branches: + only: + - /^2\.\d{6}$/ + - 'master' +install: + - cpanm --quiet --notest PkgConfig Test::CChecker Alien::zlib::Static Alien::OpenSSL::Static Alien::SNMP script: | perl Build.PL && \ ./Build && \ diff --git a/Build.PL b/Build.PL index 3d7fdeb6..fe0e4bba 100644 --- a/Build.PL +++ b/Build.PL @@ -96,6 +96,7 @@ Module::Build->new( test_requires => { 'Test::More' => '1.302083', 'Env::Path' => '0', + 'Test::Compile' => '0', 'Test::File::ShareDir::Dist' => '0', }, script_files => [ diff --git a/lib/App/Netdisco/Web.pm b/lib/App/Netdisco/Web.pm index 901eee0d..d95d1025 100644 --- a/lib/App/Netdisco/Web.pm +++ b/lib/App/Netdisco/Web.pm @@ -66,9 +66,13 @@ if (setting('template_paths') and ref [] eq ref setting('template_paths')) { # load cookie key from database setting('session_cookie_key' => undef); -my $sessions = schema('netdisco')->resultset('Session'); -my $skey = $sessions->find({id => 'dancer_session_cookie_key'}); -setting('session_cookie_key' => $skey->get_column('a_session')) if $skey; +setting('session_cookie_key' => 'this_is_for_testing_only') + if $ENV{HARNESS_ACTIVE}; +eval { + my $sessions = schema('netdisco')->resultset('Session'); + my $skey = $sessions->find({id => 'dancer_session_cookie_key'}); + setting('session_cookie_key' => $skey->get_column('a_session')) if $skey; +}; Dancer::Session::Cookie::init(session); # workaround for https://github.com/PerlDancer/Dancer/issues/935 diff --git a/lib/App/Netdisco/Worker/Plugin/DumpConfig.pm b/lib/App/Netdisco/Worker/Plugin/DumpConfig.pm index 3c57288a..d37e07a4 100644 --- a/lib/App/Netdisco/Worker/Plugin/DumpConfig.pm +++ b/lib/App/Netdisco/Worker/Plugin/DumpConfig.pm @@ -11,7 +11,8 @@ register_worker({ phase => 'main' }, sub { my $extra = $job->extra; my $config = config(); - p ($extra ? $config->{$extra} : $config); + my $dump = ($extra ? $config->{$extra} : $config); + p $dump; return Status->done('Dumped config'); }); diff --git a/xt/00-compile.t b/xt/00-compile.t new file mode 100644 index 00000000..307058af --- /dev/null +++ b/xt/00-compile.t @@ -0,0 +1,30 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +BEGIN { + use FindBin; + FindBin::again(); + + use Path::Class; + + # stuff useful locations into @INC and $PATH + unshift @INC, + dir($FindBin::RealBin)->parent->subdir('lib')->stringify, + dir($FindBin::RealBin, 'lib')->stringify; +} + +# for netdisco app config +use App::Netdisco; +use Test::Compile; + +my $test = Test::Compile->new(); + +my @plfiles = grep {$_ !~ m/(?:sshcollector|graph)/i} $test->all_pl_files(); +my @pmfiles = grep {$_ !~ m/(?:sshcollector|graph)/i} $test->all_pm_files(); + +$test->ok($test->pl_file_compiles($_), "$_ compiles") for @plfiles; +$test->ok($test->pm_file_compiles($_), "$_ compiles") for @pmfiles; + +$test->done_testing();