Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor some tests using subtest() #125

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 88 additions & 79 deletions t/cli_options.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,91 +22,100 @@
use strict;
use warnings;

use Test::More tests => 10;
use Test::More tests => 6;

use testutil;

require 'stow';

init_test_dirs();

local @ARGV = (
'-v',
'-d', "$TEST_DIR/stow",
'-t', "$TEST_DIR/target",
'dummy'
);

my ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();

is($options->{verbose}, 1, 'verbose option');
is($options->{dir}, "$TEST_DIR/stow", 'stow dir option');

my $stow = new_Stow(%$options);

is($stow->{stow_path}, "../stow" => 'stow dir');
is_deeply($pkgs_to_stow, [ 'dummy' ] => 'default to stow');

#
# Check mixed up package options
#
local @ARGV = (
'-v',
'-D', 'd1', 'd2',
'-S', 's1',
'-R', 'r1',
'-D', 'd3',
'-S', 's2', 's3',
'-R', 'r2',
);

($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
is_deeply($pkgs_to_delete, [ 'd1', 'd2', 'r1', 'd3', 'r2' ] => 'mixed deletes');
is_deeply($pkgs_to_stow, [ 's1', 'r1', 's2', 's3', 'r2' ] => 'mixed stows');

#
# Check setting deferred paths
#
local @ARGV = (
'--defer=man',
'--defer=info',
'dummy'
);
($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
is_deeply($options->{defer}, [ qr{\A(man)}, qr{\A(info)} ] => 'defer man and info');

#
# Check setting override paths
#
local @ARGV = (
'--override=man',
'--override=info',
'dummy'
);
($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
is_deeply($options->{override}, [qr{\A(man)}, qr{\A(info)}] => 'override man and info');

#
# Check setting ignored paths
#
local @ARGV = (
'--ignore=~',
'--ignore=\.#.*',
'dummy'
);
($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
is_deeply($options->{ignore}, [ qr{(~)\z}, qr{(\.#.*)\z} ] => 'ignore temp files');

#
# Check that expansion not applied.
#
local @ARGV = (
"--target=$TEST_DIR/".'$HOME',
'dummy'
);
make_path("$TEST_DIR/".'$HOME');
($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
is($options->{target}, "$TEST_DIR/".'$HOME', 'no expansion');
remove_dir("$TEST_DIR/".'$HOME');
subtest('basic CLI options', sub {
plan tests => 4;

local @ARGV = (
'-v',
'-d', "$TEST_DIR/stow",
'-t', "$TEST_DIR/target",
'dummy'
);

my ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();

is($options->{verbose}, 1, 'verbose option');
is($options->{dir}, "$TEST_DIR/stow", 'stow dir option');

my $stow = new_Stow(%$options);

is($stow->{stow_path}, "../stow" => 'stow dir');
is_deeply($pkgs_to_stow, [ 'dummy' ] => 'default to stow');
});

subtest('mixed up package options', sub {
plan tests => 2;

local @ARGV = (
'-v',
'-D', 'd1', 'd2',
'-S', 's1',
'-R', 'r1',
'-D', 'd3',
'-S', 's2', 's3',
'-R', 'r2',
);

my ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
is_deeply($pkgs_to_delete, [ 'd1', 'd2', 'r1', 'd3', 'r2' ] => 'mixed deletes');
is_deeply($pkgs_to_stow, [ 's1', 'r1', 's2', 's3', 'r2' ] => 'mixed stows');
});

subtest('setting deferred paths', sub {
plan tests => 1;

local @ARGV = (
'--defer=man',
'--defer=info',
'dummy'
);
my ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
is_deeply($options->{defer}, [ qr{\A(man)}, qr{\A(info)} ] => 'defer man and info');
});

subtest('setting override paths', sub {
plan tests => 1;

local @ARGV = (
'--override=man',
'--override=info',
'dummy'
);
my ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
is_deeply($options->{override}, [qr{\A(man)}, qr{\A(info)}] => 'override man and info');
});

subtest('setting ignored paths', sub {
plan tests => 1;

local @ARGV = (
'--ignore=~',
'--ignore=\.#.*',
'dummy'
);
my ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
is_deeply($options->{ignore}, [ qr{(~)\z}, qr{(\.#.*)\z} ] => 'ignore temp files');
});

subtest('no expansion of environment variables', sub {
plan tests => 1;

local @ARGV = (
"--target=$TEST_DIR/".'$HOME',
'dummy'
);
make_path("$TEST_DIR/".'$HOME');
my ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
is($options->{target}, "$TEST_DIR/".'$HOME', 'no expansion');
remove_dir("$TEST_DIR/".'$HOME');
});

# vim:ft=perl
Loading
Loading