diff options
Diffstat (limited to 't')
34 files changed, 345 insertions, 0 deletions
diff --git a/t/00-compile.t b/t/00-compile.t new file mode 100755 index 0000000..d7b89cb --- /dev/null +++ b/t/00-compile.t @@ -0,0 +1,8 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.010; +use Test::More; +use Test::Compile; + +all_pl_files_ok(qw{ bin/comirror bin/comirror-setup }); diff --git a/t/10-pod-coverage.t b/t/10-pod-coverage.t new file mode 100755 index 0000000..df81177 --- /dev/null +++ b/t/10-pod-coverage.t @@ -0,0 +1,8 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.010; +use Test::More; +use Test::Pod; + +all_pod_files_ok(qw{ bin/comirror bin/comirror-setup }); diff --git a/t/50-comirror.t b/t/50-comirror.t new file mode 100755 index 0000000..6adc23c --- /dev/null +++ b/t/50-comirror.t @@ -0,0 +1,59 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.010; +use Cwd; +use Test::More tests => 26; +use Test::Cmd; + +sub check_key { + my ($test, $filetype, $key, $value) = @_; + my @lines; + $test->read(\@lines, "comirror.${filetype}"); + + if(grep { $_ eq "$key\t$value\n" } @lines) { + pass("${filetype}: ${key} = ${value}"); + } + else { + fail("${filetype}: ${key} = ${value}"); + } +} + +for my $next_type (qw/ loop none /) { + + my $test = Test::Cmd->new( prog => 'bin/comirror', workdir => q{} ); + my $cwd = $test->workdir(); + + my $next_base = 'file://' . getcwd() . "/t/next-${next_type}"; + my ($str, $exit); + + ok($test, "Create Test::Cmd object ($next_type)"); + + $test->write('comirror.conf', "image_re\t${next_base}/.+\n"); + + $exit = $test->run( + chdir => $cwd, + args => "${next_base}/1.xhtml", + ); + + ok($exit == 0, 'First run: return 0'); + + isnt($test->stdout, q{}, 'First run: Non-empty stdout'); + is ($test->stderr, q{}, 'First run: Empty stderr'); + + check_key($test, 'state', 'uri', "${next_base}/4.xhtml"); + + for my $i (1 .. 5) { + ok(-e "$cwd/$i.jpg", + "$i.jpg was downloaded successfully ($next_type)"); + } + + $exit = $test->run( + chdir => $cwd, + ); + + ok(($exit >> 8) == 1, 'Second run: return 1 (no new images loaded)'); + + isnt($test->stdout, q{}, 'Second run: Non-empty stdout'); + is ($test->stderr, q{}, 'Second run: Empty stderr'); +} diff --git a/t/60-comirror-setup.t b/t/60-comirror-setup.t new file mode 100755 index 0000000..a487185 --- /dev/null +++ b/t/60-comirror-setup.t @@ -0,0 +1,62 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.010; +use Cwd; +use Test::More tests => 18; +use Test::Cmd; + +my $test; + +sub check_key { + my ($filetype, $key, $value) = @_; + my @lines; + $test->read(\@lines, "comirror.${filetype}"); + + if(grep { $_ eq "$key\t$value\n" } @lines) { + pass("${filetype}: ${key} = ${value}"); + } + else { + fail("${filetype}: ${key} = ${value}"); + } +} + +for my $test_type (qw/loop unicroak/) { + + $test = Test::Cmd->new( prog => 'bin/comirror-setup', workdir => q{} ); + my $cwd = $test->workdir(); + + my $next_base = 'file://' . getcwd() . "/t/next-${test_type}"; + my ($str, $exit); + my @links; + + ok($test, 'Create Test::Cmd object'); + + $exit = $test->run( + chdir => $cwd + ); + + ok($exit != 0, 'Not enough arguments: non-zero return'); + + is ($test->stdout, q{}, 'Not enough arguments: Nothing to stdout'); + isnt($test->stderr, q{}, 'Not enough arguments: Something to stderr'); + + for my $i (1 .. 5) { + push(@links, "${next_base}/${i}.xhtml"); + } + + $exit = $test->run( + chdir => $cwd, + args => '--batch ' . join(q{ }, @links[0, 1, 3]), + ); + + ok($exit == 0, 'Correct usage: return zero'); + + isnt($test->stdout, q{}, 'Correct usage: Something to stdout'); + is ($test->stderr, q{}, 'Correct usage: Nothing to stderr'); + + check_key('state', 'uri', $links[0]); + + check_key('conf', 'image_re', "${next_base}/.+"); + +} diff --git a/t/next-loop/1.jpg b/t/next-loop/1.jpg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/next-loop/1.jpg diff --git a/t/next-loop/1.xhtml b/t/next-loop/1.xhtml new file mode 100644 index 0000000..c0efc65 --- /dev/null +++ b/t/next-loop/1.xhtml @@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> +<div> + <img src="1.jpg"/> + <a href="2.xhtml">Next =></a> +</div> +</body> +</html> diff --git a/t/next-loop/2.jpg b/t/next-loop/2.jpg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/next-loop/2.jpg diff --git a/t/next-loop/2.xhtml b/t/next-loop/2.xhtml new file mode 100644 index 0000000..60e57e1 --- /dev/null +++ b/t/next-loop/2.xhtml @@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> +<div> + <img src="2.jpg"/> + <a href="3.xhtml">Next =></a> +</div> +</body> +</html> diff --git a/t/next-loop/3.jpg b/t/next-loop/3.jpg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/next-loop/3.jpg diff --git a/t/next-loop/3.xhtml b/t/next-loop/3.xhtml new file mode 100644 index 0000000..97eadf4 --- /dev/null +++ b/t/next-loop/3.xhtml @@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> +<div> + <img src="3.jpg"/> + <a href="4.xhtml">Next =></a> +</div> +</body> +</html> diff --git a/t/next-loop/4.jpg b/t/next-loop/4.jpg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/next-loop/4.jpg diff --git a/t/next-loop/4.xhtml b/t/next-loop/4.xhtml new file mode 100644 index 0000000..b0cf520 --- /dev/null +++ b/t/next-loop/4.xhtml @@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> +<div> + <img src="4.jpg"/> + <a href="5.xhtml">Next =></a> +</div> +</body> +</html> diff --git a/t/next-loop/5.jpg b/t/next-loop/5.jpg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/next-loop/5.jpg diff --git a/t/next-loop/5.xhtml b/t/next-loop/5.xhtml new file mode 100644 index 0000000..86ff9e8 --- /dev/null +++ b/t/next-loop/5.xhtml @@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> +<div> + <img src="5.jpg"/> + <a href="5.xhtml">Next =></a> +</div> +</body> +</html> diff --git a/t/next-none/1.jpg b/t/next-none/1.jpg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/next-none/1.jpg diff --git a/t/next-none/1.xhtml b/t/next-none/1.xhtml new file mode 100644 index 0000000..c0efc65 --- /dev/null +++ b/t/next-none/1.xhtml @@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> +<div> + <img src="1.jpg"/> + <a href="2.xhtml">Next =></a> +</div> +</body> +</html> diff --git a/t/next-none/2.jpg b/t/next-none/2.jpg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/next-none/2.jpg diff --git a/t/next-none/2.xhtml b/t/next-none/2.xhtml new file mode 100644 index 0000000..60e57e1 --- /dev/null +++ b/t/next-none/2.xhtml @@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> +<div> + <img src="2.jpg"/> + <a href="3.xhtml">Next =></a> +</div> +</body> +</html> diff --git a/t/next-none/3.jpg b/t/next-none/3.jpg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/next-none/3.jpg diff --git a/t/next-none/3.xhtml b/t/next-none/3.xhtml new file mode 100644 index 0000000..97eadf4 --- /dev/null +++ b/t/next-none/3.xhtml @@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> +<div> + <img src="3.jpg"/> + <a href="4.xhtml">Next =></a> +</div> +</body> +</html> diff --git a/t/next-none/4.jpg b/t/next-none/4.jpg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/next-none/4.jpg diff --git a/t/next-none/4.xhtml b/t/next-none/4.xhtml new file mode 100644 index 0000000..b0cf520 --- /dev/null +++ b/t/next-none/4.xhtml @@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> +<div> + <img src="4.jpg"/> + <a href="5.xhtml">Next =></a> +</div> +</body> +</html> diff --git a/t/next-none/5.jpg b/t/next-none/5.jpg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/next-none/5.jpg diff --git a/t/next-none/5.xhtml b/t/next-none/5.xhtml new file mode 100644 index 0000000..41012d9 --- /dev/null +++ b/t/next-none/5.xhtml @@ -0,0 +1,13 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> +<div> + <img src="5.jpg"/> +</div> +</body> +</html> diff --git a/t/next-unicroak/1.jpg b/t/next-unicroak/1.jpg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/next-unicroak/1.jpg diff --git a/t/next-unicroak/1.xhtml b/t/next-unicroak/1.xhtml new file mode 100644 index 0000000..9753197 --- /dev/null +++ b/t/next-unicroak/1.xhtml @@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> +<div> + <img src="1.jpg"/> + <a href="2.xhtml">Next →</a> +</div> +</body> +</html> diff --git a/t/next-unicroak/2.jpg b/t/next-unicroak/2.jpg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/next-unicroak/2.jpg diff --git a/t/next-unicroak/2.xhtml b/t/next-unicroak/2.xhtml new file mode 100644 index 0000000..b3c3969 --- /dev/null +++ b/t/next-unicroak/2.xhtml @@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> +<div> + <img src="2.jpg"/> + <a href="3.xhtml">Next →</a> +</div> +</body> +</html> diff --git a/t/next-unicroak/3.jpg b/t/next-unicroak/3.jpg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/next-unicroak/3.jpg diff --git a/t/next-unicroak/3.xhtml b/t/next-unicroak/3.xhtml new file mode 100644 index 0000000..b0488cf --- /dev/null +++ b/t/next-unicroak/3.xhtml @@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> +<div> + <img src="3.jpg"/> + <a href="4.xhtml">Next →</a> +</div> +</body> +</html> diff --git a/t/next-unicroak/4.jpg b/t/next-unicroak/4.jpg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/next-unicroak/4.jpg diff --git a/t/next-unicroak/4.xhtml b/t/next-unicroak/4.xhtml new file mode 100644 index 0000000..844854e --- /dev/null +++ b/t/next-unicroak/4.xhtml @@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> +<div> + <img src="4.jpg"/> + <a href="5.xhtml">Next →</a> +</div> +</body> +</html> diff --git a/t/next-unicroak/5.jpg b/t/next-unicroak/5.jpg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/next-unicroak/5.jpg diff --git a/t/next-unicroak/5.xhtml b/t/next-unicroak/5.xhtml new file mode 100644 index 0000000..41012d9 --- /dev/null +++ b/t/next-unicroak/5.xhtml @@ -0,0 +1,13 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> +<div> + <img src="5.jpg"/> +</div> +</body> +</html> |