t/dotfiles.t: switch to subtests

This commit is contained in:
Adam Spiers 2024-04-01 02:30:47 +01:00
parent a328c2cd4b
commit 86f03d115d

View file

@ -22,7 +22,7 @@
use strict; use strict;
use warnings; use warnings;
use Test::More tests => 11; use Test::More tests => 10;
use English qw(-no_match_vars); use English qw(-no_match_vars);
use Stow::Util qw(adjust_dotfile); use Stow::Util qw(adjust_dotfile);
@ -53,177 +53,157 @@ subtest('adjust_dotfile()', sub {
my $stow; my $stow;
# subtest("stow a dotfile marked with 'dot' prefix", sub {
# stow a dotfile marked with 'dot' prefix plan tests => 1;
# $stow = new_Stow(dir => '../stow', dotfiles => 1);
make_path('../stow/dotfiles');
make_file('../stow/dotfiles/dot-foo');
$stow = new_Stow(dir => '../stow', dotfiles => 1); $stow->plan_stow('dotfiles');
$stow->process_tasks();
is(
readlink('.foo'),
'../stow/dotfiles/dot-foo',
=> 'processed dotfile'
);
});
make_path('../stow/dotfiles'); subtest("ensure that turning off dotfile processing links files as usual", sub {
make_file('../stow/dotfiles/dot-foo'); plan tests => 1;
$stow = new_Stow(dir => '../stow', dotfiles => 0);
make_path('../stow/dotfiles');
make_file('../stow/dotfiles/dot-foo');
$stow->plan_stow('dotfiles'); $stow->plan_stow('dotfiles');
$stow->process_tasks(); $stow->process_tasks();
is( is(
readlink('.foo'), readlink('dot-foo'),
'../stow/dotfiles/dot-foo', '../stow/dotfiles/dot-foo',
=> 'processed dotfile' => 'unprocessed dotfile'
); );
# });
# ensure that turning off dotfile processing links files as usual
#
$stow = new_Stow(dir => '../stow', dotfiles => 0); subtest("stow folder marked with 'dot' prefix", sub {
plan tests => 1;
$stow = new_Stow(dir => '../stow', dotfiles => 1);
make_path('../stow/dotfiles'); make_path('../stow/dotfiles/dot-emacs');
make_file('../stow/dotfiles/dot-foo'); make_file('../stow/dotfiles/dot-emacs/init.el');
$stow->plan_stow('dotfiles'); $stow->plan_stow('dotfiles');
$stow->process_tasks(); $stow->process_tasks();
is( is(
readlink('dot-foo'), readlink('.emacs'),
'../stow/dotfiles/dot-foo', '../stow/dotfiles/dot-emacs',
=> 'unprocessed dotfile' => 'processed dotfile folder'
); );
});
subtest("process folder marked with 'dot' prefix when directory exists is target", sub {
plan tests => 1;
$stow = new_Stow(dir => '../stow', dotfiles => 1);
# make_path('../stow/dotfiles/dot-emacs.d');
# stow folder marked with 'dot' prefix make_file('../stow/dotfiles/dot-emacs.d/init.el');
# make_path('.emacs.d');
$stow = new_Stow(dir => '../stow', dotfiles => 1); $stow->plan_stow('dotfiles');
$stow->process_tasks();
is(
readlink('.emacs.d/init.el'),
'../../stow/dotfiles/dot-emacs.d/init.el',
=> 'processed dotfile folder when folder exists (1 level)'
);
});
make_path('../stow/dotfiles/dot-emacs'); subtest("process folder marked with 'dot' prefix when directory exists is target (2 levels)", sub {
make_file('../stow/dotfiles/dot-emacs/init.el'); plan tests => 1;
$stow = new_Stow(dir => '../stow', dotfiles => 1);
$stow->plan_stow('dotfiles'); make_path('../stow/dotfiles/dot-emacs.d/dot-emacs.d');
$stow->process_tasks(); make_file('../stow/dotfiles/dot-emacs.d/dot-emacs.d/init.el');
is( make_path('.emacs.d');
readlink('.emacs'),
'../stow/dotfiles/dot-emacs',
=> 'processed dotfile folder'
);
# $stow->plan_stow('dotfiles');
# process folder marked with 'dot' prefix $stow->process_tasks();
# when directory exists is target is(
# readlink('.emacs.d/.emacs.d'),
'../../stow/dotfiles/dot-emacs.d/dot-emacs.d',
=> 'processed dotfile folder exists (2 levels)'
);
});
$stow = new_Stow(dir => '../stow', dotfiles => 1); subtest("process folder marked with 'dot' prefix when directory exists is target", sub {
plan tests => 1;
$stow = new_Stow(dir => '../stow', dotfiles => 1);
make_path('../stow/dotfiles/dot-emacs.d'); make_path('../stow/dotfiles/dot-one/dot-two');
make_file('../stow/dotfiles/dot-emacs.d/init.el'); make_file('../stow/dotfiles/dot-one/dot-two/three');
make_path('.emacs.d'); make_path('.one/.two');
$stow->plan_stow('dotfiles'); $stow->plan_stow('dotfiles');
$stow->process_tasks(); $stow->process_tasks();
is( is(
readlink('.emacs.d/init.el'), readlink('./.one/.two/three'),
'../../stow/dotfiles/dot-emacs.d/init.el', '../../../stow/dotfiles/dot-one/dot-two/three',
=> 'processed dotfile folder when folder exists (1 level)' => 'processed dotfile 2 folder exists (2 levels)'
); );
# });
# process folder marked with 'dot' prefix
# when directory exists is target (2 levels)
#
$stow = new_Stow(dir => '../stow', dotfiles => 1); subtest("dot-. should not have that part expanded.", sub {
plan tests => 2;
$stow = new_Stow(dir => '../stow', dotfiles => 1);
make_path('../stow/dotfiles/dot-emacs.d/dot-emacs.d'); make_path('../stow/dotfiles');
make_file('../stow/dotfiles/dot-emacs.d/dot-emacs.d/init.el'); make_file('../stow/dotfiles/dot-');
make_path('.emacs.d');
$stow->plan_stow('dotfiles'); make_path('../stow/dotfiles/dot-.');
$stow->process_tasks(); make_file('../stow/dotfiles/dot-./foo');
is(
readlink('.emacs.d/.emacs.d'),
'../../stow/dotfiles/dot-emacs.d/dot-emacs.d',
=> 'processed dotfile folder exists (2 levels)'
);
# $stow->plan_stow('dotfiles');
# process folder marked with 'dot' prefix $stow->process_tasks();
# when directory exists is target is(
# readlink('dot-'),
'../stow/dotfiles/dot-',
=> 'processed dotfile'
);
is(
readlink('dot-.'),
'../stow/dotfiles/dot-.',
=> 'unprocessed dotfile'
);
});
$stow = new_Stow(dir => '../stow', dotfiles => 1); subtest("simple unstow scenario", sub {
plan tests => 3;
$stow = new_Stow(dir => '../stow', dotfiles => 1);
make_path('../stow/dotfiles/dot-one/dot-two'); make_path('../stow/dotfiles');
make_file('../stow/dotfiles/dot-one/dot-two/three'); make_file('../stow/dotfiles/dot-bar');
make_path('.one/.two'); make_link('.bar', '../stow/dotfiles/dot-bar');
$stow->plan_stow('dotfiles'); $stow->plan_unstow('dotfiles');
$stow->process_tasks(); $stow->process_tasks();
is( is($stow->get_conflict_count, 0);
readlink('./.one/.two/three'), ok(-f '../stow/dotfiles/dot-bar');
'../../../stow/dotfiles/dot-one/dot-two/three', ok(! -e '.bar' => 'unstow a simple dotfile');
=> 'processed dotfile 2 folder exists (2 levels)' });
);
subtest("unstow process folder marked with 'dot' prefix when directory exists is target", sub {
plan tests => 4;
$stow = new_Stow(dir => '../stow', dotfiles => 1);
# make_path('../stow/dotfiles/dot-emacs.d');
# "$DOT_PREFIX." should not have that part expanded. make_file('../stow/dotfiles/dot-emacs.d/init.el');
# make_path('.emacs.d');
make_link('.emacs.d/init.el', '../../stow/dotfiles/dot-emacs.d/init.el');
$stow = new_Stow(dir => '../stow', dotfiles => 1); $stow->plan_unstow('dotfiles');
$stow->process_tasks();
make_path('../stow/dotfiles'); is($stow->get_conflict_count, 0);
make_file('../stow/dotfiles/dot-'); ok(-f '../stow/dotfiles/dot-emacs.d/init.el');
ok(! -e '.emacs.d/init.el');
make_path('../stow/dotfiles/dot-.'); ok(-d '.emacs.d/' => 'unstow dotfile folder when folder already exists');
make_file('../stow/dotfiles/dot-./foo'); });
$stow->plan_stow('dotfiles');
$stow->process_tasks();
is(
readlink('dot-'),
'../stow/dotfiles/dot-',
=> 'processed dotfile'
);
is(
readlink('dot-.'),
'../stow/dotfiles/dot-.',
=> 'unprocessed dotfile'
);
#
# simple unstow scenario
#
$stow = new_Stow(dir => '../stow', dotfiles => 1);
make_path('../stow/dotfiles');
make_file('../stow/dotfiles/dot-bar');
make_link('.bar', '../stow/dotfiles/dot-bar');
$stow->plan_unstow('dotfiles');
$stow->process_tasks();
ok(
$stow->get_conflict_count == 0 &&
-f '../stow/dotfiles/dot-bar' && ! -e '.bar'
=> 'unstow a simple dotfile'
);
#
# unstow process folder marked with 'dot' prefix
# when directory exists is target
#
$stow = new_Stow(dir => '../stow', dotfiles => 1);
make_path('../stow/dotfiles/dot-emacs.d');
make_file('../stow/dotfiles/dot-emacs.d/init.el');
make_path('.emacs.d');
make_link('.emacs.d/init.el', '../../stow/dotfiles/dot-emacs.d/init.el');
$stow->plan_unstow('dotfiles');
$stow->process_tasks();
ok(
$stow->get_conflict_count == 0 &&
-f '../stow/dotfiles/dot-emacs.d/init.el' &&
! -e '.emacs.d/init.el' &&
-d '.emacs.d/'
=> 'unstow dotfile folder when folder already exists'
);