aboutsummaryrefslogtreecommitdiff
path: root/t/Test
diff options
context:
space:
mode:
authorSlack Coder <slackcoder@server.ky>2024-11-28 09:59:36 -0500
committerSlack Coder <slackcoder@server.ky>2025-02-19 09:55:01 -0500
commit24493e32d8548110c514db9bc09efb5aba276ca5 (patch)
tree80319bacf6eb845741beb8d331969884495d6f4c /t/Test
parent82a520dcb6f6cfe538c68fd04a8a7b94f3b177c2 (diff)
downloadsbotools2-24493e32d8548110c514db9bc09efb5aba276ca5.tar.xz
Set To Do branch
Diffstat (limited to 't/Test')
-rwxr-xr-xt/Test/Execute.pm118
-rw-r--r--t/Test/Sbotools.pm179
2 files changed, 0 insertions, 297 deletions
diff --git a/t/Test/Execute.pm b/t/Test/Execute.pm
deleted file mode 100755
index e319c2e..0000000
--- a/t/Test/Execute.pm
+++ /dev/null
@@ -1,118 +0,0 @@
-package Test::Execute;
-
-use 5.16.0;
-use strict;
-use warnings FATAL => 'all';
-
-use Test::More;
-use Capture::Tiny qw/ capture_merged /;
-use Exporter 'import';
-use Carp 'croak';
-use Scalar::Util 'reftype';
-
-our $VERSION = '0.001';
-
-our @EXPORT = qw(
- run
- script
- $path
-);
-
-our $path = "";
-
-sub run {
- my %args = (
- exit => 0,
- cmd => [],
- input => undef,
- test => 1,
- expected => undef,
- name => undef,
- @_
- );
-
- my @cmd = @{ $args{cmd} };
- return undef unless @cmd; # no command to run
-
- my ($exit, $input, $test, $expected, $name, $note) =
- @args{qw/ exit input test expected name note /};
-
- my ($output, $return) = capture_merged {
- my $ret;
- if (defined $input) {
- my $pid = open (my $fh, '|-', @cmd);
- last unless $pid;
- print { $fh } $input or last;
- close $fh;
- $ret = $? >> 8;
- } else {
- $ret = system(@cmd) && $? >> 8;
- }
- };
-
- if ($note) {
- note sprintf "Exit value: %s", $return // '<undef>';
- note "Output: $output";
- }
-
- if (not $test) {
- if (defined $expected and ref $expected eq 'Regexp') {
- return $output =~ $expected;
- } elsif (defined $expected and ref $expected eq 'CODE') {
- local $_ = $output;
- return $expected->($output);
- }
- return $return;
- }
-
- $name //= "Testing run of @cmd";
- local $Test::Builder::Level = $Test::Builder::Level + 2;
- subtest $name => sub {
- plan tests => 2;
-
- # 1: Test output
- if (not defined $expected) {
- SKIP: { skip "Expected output undefined", 1 }
- } elsif (ref $expected eq 'Regexp') {
- like ($output, $expected, "$name - output");
- } elsif (ref $expected eq 'CODE') {
- local $_ = $output;
- ok ($expected->($output), "$name - output") or note "Output: $output";
- } else {
- is ($output, $expected, "$name - output");
- }
-
- # 2: Test exit value
- if (not defined $exit) {
- SKIP: { skip "Expected exit value undefined", 1 }
- } else {
- is ($return, $exit, "$name - exit value");
- }
- };
-
-}
-
-sub script {
- my @cmd;
- while (@_ and not defined reftype($_[0])) {
- my $arg = shift @_;
- push @cmd, $arg;
- }
-
- my %args;
- if (@_ and reftype($_[0]) eq 'HASH') { %args = %{ $_[0] }; }
- elsif (@_) { croak "Unknown argument passed: $_[0]"; }
- if (exists $args{cmd} and @cmd) { croak "More than one command passed"; }
- if (exists $args{cmd}) { @cmd = @{ $args{cmd} }; }
-
- my $cmd = shift @cmd;
- if (not defined $cmd) { croak "No command passed"; }
- $args{name} //= "Testing script run of $cmd @cmd";
- my @lib = map { "-I$_" } @INC;
- @cmd = ($^X, @lib, "$path$cmd", @cmd);
-
- $args{cmd} = \@cmd;
- return run(%args);
-}
-
-1;
diff --git a/t/Test/Sbotools.pm b/t/Test/Sbotools.pm
deleted file mode 100644
index 6f181ea..0000000
--- a/t/Test/Sbotools.pm
+++ /dev/null
@@ -1,179 +0,0 @@
-package Test::Sbotools;
-
-use strict;
-use warnings;
-
-use Exporter 'import';
-use Test::More;
-use Test::Execute;
-use FindBin '$RealBin';
-use Capture::Tiny 'capture_merged';
-use Test::Exit;
-use lib "$RealBin/../SBO-Lib/lib";
-
-# From Test::Execute
-$path = "$RealBin/../";
-
-our @EXPORT_OK = qw/
- sbocheck
- sboclean
- sboconfig
- sbofind
- sboinstall
- sboremove
- sbosnap
- sboupgrade
- set_noclean
- set_distclean
- set_gpg_verify
- set_jobs
- set_repo
- set_lo
- set_version
- set_pkg_dir
- set_sbo_home
- make_slackbuilds_txt
- restore_perf_dummy
- replace_tags_txt
- load
-/;
-
-local $Test::Builder::Level = $Test::Builder::Level + 1;
-
-sub sbocheck { script('sbocheck', @_); }
-sub sboclean { script('sboclean', @_); }
-sub sboconfig { script('sboconfig', @_); }
-sub sbofind { script('sbofind', @_); }
-sub sboinstall { script('sboinstall', @_); }
-sub sboremove { script('sboremove', @_); }
-sub sbosnap { script('sbosnap', @_); }
-sub sboupgrade { script('sboupgrade', @_); }
-
-sub set_noclean { _set_config('NOCLEAN', @_); }
-sub set_distclean { _set_config('DISTCLEAN', @_); }
-sub set_gpg_verify { _set_config('GPG_KEY', @_); }
-sub set_jobs { _set_config('JOBS', @_); }
-sub set_pkg_dir { _set_config('PKG_DIR', @_); }
-sub set_sbo_home { _set_config('SBO_HOME', @_); }
-sub set_lo { _set_config('LOCAL_OVERRIDES', @_); }
-sub set_version { _set_config('SLACKWARE_VERSION', @_); }
-
-my $sbt = 0;
-my $repo = 0;
-sub set_repo {
- _set_config('REPO', @_);
- if (-e "/usr/sbo/repo" and not $repo) {
- $repo = 1;
- system('mv', '/usr/sbo/repo', "/tmp/repo.backup");
-
- # if $sbt is true, the SLACKBUILDS.TXT has been created by
- # make_slackbuilds_txt and should not be backed up
- if ($sbt) { system('rm', "/tmp/repo.backup/SLACKBUILDS.TXT"); }
- }
-}
-
-my %config;
-my %settings = (
- DISTCLEAN => '-d',
- GPG_KEY => '-g',
- JOBS => '-j',
- LOCAL_OVERRIDES => '-o',
- NOCLEAN => '-c',
- PKG_DIR => '-p',
- REPO => '-r',
- SBO_HOME => '-s',
- SLACKWARE_VERSION => '-V',
-);
-sub _set_config {
- my ($config, $value) = @_;
-
- # if %config is empty, populate it
- if (not %config) {
- sboconfig('-l', { test => 0, expected =>
- sub {
- my $text = shift;
- foreach my $setting (keys %settings) { $text =~ /\Q$setting\E=(.*)/ and $config{$setting} = $1 // 'FALSE'; }
- },
- });
- }
-
- if (defined $value) {
- sboconfig($settings{$config}, $value, { test => 0 });
- note "Saving original value of '$config': $config{$config}";
- } else {
- sboconfig($settings{$config}, $config{$config}, { test => 0 });
- }
-}
-
-my $sbtn = "/usr/sbo/repo/SLACKBUILDS.TXT";
-sub make_slackbuilds_txt {
- if (not -e $sbtn) { $sbt = 1; system('mkdir', '-p', '/usr/sbo/repo'); system('touch', $sbtn); }
-}
-
-sub restore_perf_dummy {
- if (!-e '/usr/sbo/distfiles/perf.dummy') {
- system('mkdir', '-p', '/usr/sbo/distfiles');
- system('cp', "$RealBin/travis-deps/perf.dummy", '/usr/sbo/distfiles');
- }
-}
-
-my $tags = 0;
-my $tags_txt = '/usr/sbo/repo/TAGS.txt';
-sub replace_tags_txt {
- if (-e $tags_txt) {
- if (! $tags) {
- $tags = 2;
- rename $tags_txt, "$tags_txt.bak";
- }
- } else {
- $tags = 1 if $tags == 0;
- }
-
- system('mkdir', '-p', '/usr/sbo/repo');
- open my $fh, '>', $tags_txt;
- print $fh $_ for @_;
- close $fh;
-}
-
-# Restore original values when exiting
-END {
- if (%config) {
- _set_config($_) for keys %settings;
- }
- if ($sbt) {
- system(qw!rm -rf!, $sbtn);
- }
- if ($repo) {
- system(qw! rm -rf /usr/sbo/repo !);
- system('mv', "/tmp/repo.backup", '/usr/sbo/repo');
- }
- if ($tags) {
- system(qw!rm -rf !, $tags_txt);
- }
- if ($tags == 2) {
- rename "$tags_txt.bak", $tags_txt;
- }
-}
-
-sub load {
- my ($script, %opts) = @_;
-
- local @ARGV = exists $opts{argv} ? @{ $opts{argv} } : '-h';
- my ($ret, $exit, $out, $do_err);
- my $eval = eval {
- $out = capture_merged { $exit = exit_code {
- package main;
- $ret = do "$RealBin/../$script";
- $do_err = $@;
- }; };
- 1;
- };
- my $err = $@;
-
- my $explain = { ret => $ret, exit => $exit, out => $out, eval => $eval, err => $err, do_err => $do_err };
- note explain $explain if $opts{explain};
- return $explain;
-}
-
-
-1;