From e2834f606a50144ab92e54db830d2fdb06102d78 Mon Sep 17 00:00:00 2001 From: Andreas Guldstrand Date: Thu, 26 May 2016 00:21:12 +0200 Subject: Rename some test files --- t/19-pkg-dir.t | 84 ++++++++++++++++++++++++++++++++++++++++++++ t/20-config.t | 19 ++++++++++ t/21-pkg-dir.t | 84 -------------------------------------------- t/21-slackware-version.t | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ t/22-config.t | 19 ---------- t/22-race.t | 33 ++++++++++++++++++ t/23-slackware-version.t | 91 ------------------------------------------------ t/24-race.t | 33 ------------------ 8 files changed, 227 insertions(+), 227 deletions(-) create mode 100755 t/19-pkg-dir.t create mode 100755 t/20-config.t delete mode 100755 t/21-pkg-dir.t create mode 100755 t/21-slackware-version.t delete mode 100755 t/22-config.t create mode 100755 t/22-race.t delete mode 100755 t/23-slackware-version.t delete mode 100755 t/24-race.t (limited to 't') diff --git a/t/19-pkg-dir.t b/t/19-pkg-dir.t new file mode 100755 index 0000000..db44118 --- /dev/null +++ b/t/19-pkg-dir.t @@ -0,0 +1,84 @@ +#!/usr/bin/env perl + +use 5.16.0; +use strict; +use warnings FATAL => 'all'; +use Test::More; +use Capture::Tiny qw/ capture_merged /; +use FindBin '$RealBin'; +use lib $RealBin; +use Test::Sbotools qw/ set_pkg_dir make_slackbuilds_txt set_lo sboconfig sboinstall sboupgrade /; +use File::Temp 'tempdir'; + +if ($ENV{TEST_INSTALL}) { + plan tests => 10; +} else { + plan skip_all => 'Only run these tests if TEST_INSTALL=1'; +} +$ENV{TEST_ONLINE} //= 0; + +sub cleanup { + capture_merged { + system(qw!/sbin/removepkg nonexistentslackbuild!); + system(qw!/sbin/removepkg nonexistentslackbuild4!); + system(qw!/sbin/removepkg nonexistentslackbuild5!); + unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy"; + unlink "$RealBin/LO2/nonexistentslackbuild/perf.dummy"; + unlink "$RealBin/LO2/nonexistentslackbuild4/perf.dummy"; + unlink "$RealBin/LO2/nonexistentslackbuild5/perf.dummy"; + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.0!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.1!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-1.1!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-1.1!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild4!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild5!); + }; +} + +cleanup(); +make_slackbuilds_txt(); +set_lo("$RealBin/LO"); +my $pkgdir = tempdir(CLEANUP => 1); +set_pkg_dir($pkgdir); + +# 1-2: install creates package in PKG_DIR +sboinstall 'nonexistentslackbuild', { input => "y\ny", expected => qr!\Qnonexistentslackbuild-1.0-noarch-1_SBo.tgz stored in $pkgdir! }; +ok (-f "$pkgdir/nonexistentslackbuild-1.0-noarch-1_SBo.tgz", 'nonexistentslackbuild-1.0-noarch-1_SBo.tgz is in PKG_DIR'); + +# 3-4: upgrading also creates package in PKG_DIR +set_lo("$RealBin/LO2"); +sboupgrade 'nonexistentslackbuild', { input => "y\ny", expected => qr!\Qnonexistentslackbuild-1.1-noarch-1_SBo.tgz stored in $pkgdir! }; +ok (-f "$pkgdir/nonexistentslackbuild-1.1-noarch-1_SBo.tgz", 'nonexistentslackbuild-1.1-noarch-1_SBo.tgz is in PKG_DIR'); + +# 5-7: installing with deps also creates packages in PKG_DIR +sboinstall 'nonexistentslackbuild4', { input => "y\ny\ny", expected => sub { /\Qnonexistentslackbuild4-1.1-noarch-1_SBo.tgz stored in $pkgdir/ and /\Qnonexistentslackbuild5-1.1-noarch-1_SBo.tgz stored in $pkgdir/ } }; +ok (-f "$pkgdir/nonexistentslackbuild4-1.1-noarch-1_SBo.tgz", 'nonexistentslackbuild4-1.1-noarch-1_SBo.tgz is in PKG_DIR'); +ok (-f "$pkgdir/nonexistentslackbuild5-1.1-noarch-1_SBo.tgz", 'nonexistentslackbuild5-1.1-noarch-1_SBo.tgz is in PKG_DIR'); + +capture_merged { + system(qw/ rm -rf /, $pkgdir); + system(qw! /sbin/removepkg nonexistentslackbuild !); +}; + +# 8-9: make sure PKG_DIR gets recreated +sboinstall 'nonexistentslackbuild', { input => "y\ny", expected => qr!\Qnonexistentslackbuild-1.1-noarch-1_SBo.tgz stored in $pkgdir! }; +ok (-f "$pkgdir/nonexistentslackbuild-1.1-noarch-1_SBo.tgz", 'nonexistentslackbuild-1.1-noarch-1_SBo.tgz is in PKG_DIR'); + +capture_merged { + system(qw/ rm -rf /, $pkgdir ); + system(qw! /sbin/removepkg nonexistentslackbuild !); + system('touch', $pkgdir); +}; + +# 10: creating PKG_DIR should fail properly +sboinstall 'nonexistentslackbuild', { input => "y\ny", expected => sub { /\QUnable to create $pkgdir/ and /\Qnonexistentslackbuild-1.1-noarch-1_SBo.tgz left in / } }; + +capture_merged { + system('rm', $pkgdir); +}; + +# Cleanup +END { + cleanup(); +} diff --git a/t/20-config.t b/t/20-config.t new file mode 100755 index 0000000..9f1d48c --- /dev/null +++ b/t/20-config.t @@ -0,0 +1,19 @@ +#!/usr/bin/env perl + +use 5.16.0; +use strict; +use warnings FATAL => 'all'; +use Test::More; +use FindBin '$RealBin'; +use lib $RealBin; +use Test::Sbotools qw/ sboconfig /; + +plan tests => 7; + +sboconfig '-c', 'invalid', { exit => 1, expected => "You have provided an invalid parameter for -c\n" }; +sboconfig '-d', 'invalid', { exit => 1, expected => "You have provided an invalid parameter for -d\n" }; +sboconfig '-j', 'invalid', { exit => 1, expected => "You have provided an invalid parameter for -j\n" }; +sboconfig '-p', 'invalid', { exit => 1, expected => "You have provided an invalid parameter for -p\n" }; +sboconfig '-s', 'invalid', { exit => 1, expected => "You have provided an invalid parameter for -s\n" }; +sboconfig '-o', 'invalid', { exit => 1, expected => "You have provided an invalid parameter for -o\n" }; +sboconfig '-V', 'invalid', { exit => 1, expected => "You have provided an invalid parameter for -V\n" }; diff --git a/t/21-pkg-dir.t b/t/21-pkg-dir.t deleted file mode 100755 index db44118..0000000 --- a/t/21-pkg-dir.t +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/env perl - -use 5.16.0; -use strict; -use warnings FATAL => 'all'; -use Test::More; -use Capture::Tiny qw/ capture_merged /; -use FindBin '$RealBin'; -use lib $RealBin; -use Test::Sbotools qw/ set_pkg_dir make_slackbuilds_txt set_lo sboconfig sboinstall sboupgrade /; -use File::Temp 'tempdir'; - -if ($ENV{TEST_INSTALL}) { - plan tests => 10; -} else { - plan skip_all => 'Only run these tests if TEST_INSTALL=1'; -} -$ENV{TEST_ONLINE} //= 0; - -sub cleanup { - capture_merged { - system(qw!/sbin/removepkg nonexistentslackbuild!); - system(qw!/sbin/removepkg nonexistentslackbuild4!); - system(qw!/sbin/removepkg nonexistentslackbuild5!); - unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy"; - unlink "$RealBin/LO2/nonexistentslackbuild/perf.dummy"; - unlink "$RealBin/LO2/nonexistentslackbuild4/perf.dummy"; - unlink "$RealBin/LO2/nonexistentslackbuild5/perf.dummy"; - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.0!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.1!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-1.1!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-1.1!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild4!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild5!); - }; -} - -cleanup(); -make_slackbuilds_txt(); -set_lo("$RealBin/LO"); -my $pkgdir = tempdir(CLEANUP => 1); -set_pkg_dir($pkgdir); - -# 1-2: install creates package in PKG_DIR -sboinstall 'nonexistentslackbuild', { input => "y\ny", expected => qr!\Qnonexistentslackbuild-1.0-noarch-1_SBo.tgz stored in $pkgdir! }; -ok (-f "$pkgdir/nonexistentslackbuild-1.0-noarch-1_SBo.tgz", 'nonexistentslackbuild-1.0-noarch-1_SBo.tgz is in PKG_DIR'); - -# 3-4: upgrading also creates package in PKG_DIR -set_lo("$RealBin/LO2"); -sboupgrade 'nonexistentslackbuild', { input => "y\ny", expected => qr!\Qnonexistentslackbuild-1.1-noarch-1_SBo.tgz stored in $pkgdir! }; -ok (-f "$pkgdir/nonexistentslackbuild-1.1-noarch-1_SBo.tgz", 'nonexistentslackbuild-1.1-noarch-1_SBo.tgz is in PKG_DIR'); - -# 5-7: installing with deps also creates packages in PKG_DIR -sboinstall 'nonexistentslackbuild4', { input => "y\ny\ny", expected => sub { /\Qnonexistentslackbuild4-1.1-noarch-1_SBo.tgz stored in $pkgdir/ and /\Qnonexistentslackbuild5-1.1-noarch-1_SBo.tgz stored in $pkgdir/ } }; -ok (-f "$pkgdir/nonexistentslackbuild4-1.1-noarch-1_SBo.tgz", 'nonexistentslackbuild4-1.1-noarch-1_SBo.tgz is in PKG_DIR'); -ok (-f "$pkgdir/nonexistentslackbuild5-1.1-noarch-1_SBo.tgz", 'nonexistentslackbuild5-1.1-noarch-1_SBo.tgz is in PKG_DIR'); - -capture_merged { - system(qw/ rm -rf /, $pkgdir); - system(qw! /sbin/removepkg nonexistentslackbuild !); -}; - -# 8-9: make sure PKG_DIR gets recreated -sboinstall 'nonexistentslackbuild', { input => "y\ny", expected => qr!\Qnonexistentslackbuild-1.1-noarch-1_SBo.tgz stored in $pkgdir! }; -ok (-f "$pkgdir/nonexistentslackbuild-1.1-noarch-1_SBo.tgz", 'nonexistentslackbuild-1.1-noarch-1_SBo.tgz is in PKG_DIR'); - -capture_merged { - system(qw/ rm -rf /, $pkgdir ); - system(qw! /sbin/removepkg nonexistentslackbuild !); - system('touch', $pkgdir); -}; - -# 10: creating PKG_DIR should fail properly -sboinstall 'nonexistentslackbuild', { input => "y\ny", expected => sub { /\QUnable to create $pkgdir/ and /\Qnonexistentslackbuild-1.1-noarch-1_SBo.tgz left in / } }; - -capture_merged { - system('rm', $pkgdir); -}; - -# Cleanup -END { - cleanup(); -} diff --git a/t/21-slackware-version.t b/t/21-slackware-version.t new file mode 100755 index 0000000..af13e6a --- /dev/null +++ b/t/21-slackware-version.t @@ -0,0 +1,91 @@ +#!/usr/bin/env perl + +use 5.16.0; +use strict; +use warnings FATAL => 'all'; +use Test::More; +use Capture::Tiny qw/ capture_merged /; +use FindBin '$RealBin'; +use lib $RealBin; +use lib "$RealBin/../SBO-Lib/lib"; +use Test::Execute; + +if ($ENV{TRAVIS}) { + plan tests => 2; +} else { + plan skip_all => "Only run these tests if we're running under Travis CI"; +} + +$path = "$RealBin/../"; + +sub cleanup { + capture_merged { + rename "/etc/slackware-version.moved", "/etc/slackware-version"; + }; +} + +sub move_slackware_version { + state $moved = 0; + my $fname = "/etc/slackware-version"; + if ($_[0]) { + if ($moved) { return rename "$fname.moved", $fname; } + } else { rename($fname, "$fname.moved") and $moved = 1; } +} + +sub set_ver { + state $set = 0; + state $ver; + if ($_[0]) { + if ($set) { script (qw/ sboconfig -V /, $ver, { test => 0 }); } + } else { + ($ver) = script (qw/ sboconfig -l /, { expected => qr/SLACKWARE_VERSION=(.*)/, test => 0 }); + $ver //= 'FALSE'; + note "Saving original value of SLACKWARE_VERSION: $ver"; + $set = 1; + script (qw/ sboconfig -V FALSE /, { test => 0 }); + } +} + +sub set_repo { + state $set = 0; + state $orig; + if ($_[0]) { + if ($set) { + capture_merged { system(qw!rm -rf /usr/sbo/repo!); system('mv', "$RealBin/repo.backup", "/usr/sbo/repo"); } if -e "$RealBin/repo.backup"; + script (qw/ sboconfig -r /, $orig, { test => 0 }); + } + } else { + ($orig) = script (qw/ sboconfig -l /, { expected => qr/REPO=(.*)/, test => 0 }); + $orig //= 'FALSE'; + note "Saving original value of REPO: $orig"; + $set = 1; + script (qw/ sboconfig -r FALSE /, { test => 0 }); + capture_merged { system(qw! mv /usr/sbo/repo !, "$RealBin/repo.backup"); } if -e "/usr/sbo/repo"; + } +} + + +set_repo(); +set_ver(); +move_slackware_version(); + +# 1: Fail properly when no /etc/slackware-version file exists +script (qw/ sbocheck /, { exit => 2, expected => qr!^A fatal script error has occurred:\nopen_fh, /etc/slackware-version is not a file\nExiting\.$!m }); + +# 2: Fail properly when /etc/slackware-version has a too old version +if (open(my $fh, '>', '/etc/slackware-version')) { + print $fh "Slackware 13.37\n"; + close $fh; + + script (qw/ sbocheck /, { exit => 1, expected => qr!^Unsupported Slackware version: 13\.37$!m }); + unlink '/etc/slackware-version'; +} else { + fail "Could not write old version to /etc/slackware-version."; +} + +# Cleanup +END { + move_slackware_version('move'); + set_ver('restore'); + set_repo('restore'); +} diff --git a/t/22-config.t b/t/22-config.t deleted file mode 100755 index 9f1d48c..0000000 --- a/t/22-config.t +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env perl - -use 5.16.0; -use strict; -use warnings FATAL => 'all'; -use Test::More; -use FindBin '$RealBin'; -use lib $RealBin; -use Test::Sbotools qw/ sboconfig /; - -plan tests => 7; - -sboconfig '-c', 'invalid', { exit => 1, expected => "You have provided an invalid parameter for -c\n" }; -sboconfig '-d', 'invalid', { exit => 1, expected => "You have provided an invalid parameter for -d\n" }; -sboconfig '-j', 'invalid', { exit => 1, expected => "You have provided an invalid parameter for -j\n" }; -sboconfig '-p', 'invalid', { exit => 1, expected => "You have provided an invalid parameter for -p\n" }; -sboconfig '-s', 'invalid', { exit => 1, expected => "You have provided an invalid parameter for -s\n" }; -sboconfig '-o', 'invalid', { exit => 1, expected => "You have provided an invalid parameter for -o\n" }; -sboconfig '-V', 'invalid', { exit => 1, expected => "You have provided an invalid parameter for -V\n" }; diff --git a/t/22-race.t b/t/22-race.t new file mode 100755 index 0000000..07b9b74 --- /dev/null +++ b/t/22-race.t @@ -0,0 +1,33 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use Test::Exit; +use FindBin '$RealBin'; +use lib "$RealBin/../SBO-Lib/lib"; +use SBO::Lib qw/ open_fh /; +use Capture::Tiny qw/ capture_merged /; +use File::Temp 'tempdir'; + +plan tests => 1; + +sub emulate_race { + my ($file, $caller) = @_; + $caller = "SBO::Lib::$caller"; + + no warnings 'redefine'; + *_race::cond = sub { unlink $file if $caller eq (caller(1))[3]; }; +} + +# 1: emulate race condition for open_fh +{ + my $tempdir = tempdir(CLEANUP => 1); + my $file = "$tempdir/foo"; + system('touch', $file); + + emulate_race($file, 'open_fh'); + + my ($fh, $exit) = open_fh $file, '<'; + is ($exit, 6, 'open_fh returned exit value 6'); +} diff --git a/t/23-slackware-version.t b/t/23-slackware-version.t deleted file mode 100755 index af13e6a..0000000 --- a/t/23-slackware-version.t +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env perl - -use 5.16.0; -use strict; -use warnings FATAL => 'all'; -use Test::More; -use Capture::Tiny qw/ capture_merged /; -use FindBin '$RealBin'; -use lib $RealBin; -use lib "$RealBin/../SBO-Lib/lib"; -use Test::Execute; - -if ($ENV{TRAVIS}) { - plan tests => 2; -} else { - plan skip_all => "Only run these tests if we're running under Travis CI"; -} - -$path = "$RealBin/../"; - -sub cleanup { - capture_merged { - rename "/etc/slackware-version.moved", "/etc/slackware-version"; - }; -} - -sub move_slackware_version { - state $moved = 0; - my $fname = "/etc/slackware-version"; - if ($_[0]) { - if ($moved) { return rename "$fname.moved", $fname; } - } else { rename($fname, "$fname.moved") and $moved = 1; } -} - -sub set_ver { - state $set = 0; - state $ver; - if ($_[0]) { - if ($set) { script (qw/ sboconfig -V /, $ver, { test => 0 }); } - } else { - ($ver) = script (qw/ sboconfig -l /, { expected => qr/SLACKWARE_VERSION=(.*)/, test => 0 }); - $ver //= 'FALSE'; - note "Saving original value of SLACKWARE_VERSION: $ver"; - $set = 1; - script (qw/ sboconfig -V FALSE /, { test => 0 }); - } -} - -sub set_repo { - state $set = 0; - state $orig; - if ($_[0]) { - if ($set) { - capture_merged { system(qw!rm -rf /usr/sbo/repo!); system('mv', "$RealBin/repo.backup", "/usr/sbo/repo"); } if -e "$RealBin/repo.backup"; - script (qw/ sboconfig -r /, $orig, { test => 0 }); - } - } else { - ($orig) = script (qw/ sboconfig -l /, { expected => qr/REPO=(.*)/, test => 0 }); - $orig //= 'FALSE'; - note "Saving original value of REPO: $orig"; - $set = 1; - script (qw/ sboconfig -r FALSE /, { test => 0 }); - capture_merged { system(qw! mv /usr/sbo/repo !, "$RealBin/repo.backup"); } if -e "/usr/sbo/repo"; - } -} - - -set_repo(); -set_ver(); -move_slackware_version(); - -# 1: Fail properly when no /etc/slackware-version file exists -script (qw/ sbocheck /, { exit => 2, expected => qr!^A fatal script error has occurred:\nopen_fh, /etc/slackware-version is not a file\nExiting\.$!m }); - -# 2: Fail properly when /etc/slackware-version has a too old version -if (open(my $fh, '>', '/etc/slackware-version')) { - print $fh "Slackware 13.37\n"; - close $fh; - - script (qw/ sbocheck /, { exit => 1, expected => qr!^Unsupported Slackware version: 13\.37$!m }); - unlink '/etc/slackware-version'; -} else { - fail "Could not write old version to /etc/slackware-version."; -} - -# Cleanup -END { - move_slackware_version('move'); - set_ver('restore'); - set_repo('restore'); -} diff --git a/t/24-race.t b/t/24-race.t deleted file mode 100755 index 07b9b74..0000000 --- a/t/24-race.t +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; -use Test::More; -use Test::Exit; -use FindBin '$RealBin'; -use lib "$RealBin/../SBO-Lib/lib"; -use SBO::Lib qw/ open_fh /; -use Capture::Tiny qw/ capture_merged /; -use File::Temp 'tempdir'; - -plan tests => 1; - -sub emulate_race { - my ($file, $caller) = @_; - $caller = "SBO::Lib::$caller"; - - no warnings 'redefine'; - *_race::cond = sub { unlink $file if $caller eq (caller(1))[3]; }; -} - -# 1: emulate race condition for open_fh -{ - my $tempdir = tempdir(CLEANUP => 1); - my $file = "$tempdir/foo"; - system('touch', $file); - - emulate_race($file, 'open_fh'); - - my ($fh, $exit) = open_fh $file, '<'; - is ($exit, 6, 'open_fh returned exit value 6'); -} -- cgit v1.2.3