summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-03-18 19:01:58 +0100
committerDaniel Friesel <derf@finalrewind.org>2011-03-18 19:01:58 +0100
commitf9553f3e2b7f21080ce7974909e92d251aaae528 (patch)
tree7d08189cca69cde69e64d98e1a514942a2f04e14
parentfef20e838cf1eeacacdae0491a13727b4ad8b7e9 (diff)
Add tests
-rw-r--r--Makefile5
-rwxr-xr-xt/01-compile-pl.t8
-rw-r--r--t/60-regression.t69
-rw-r--r--t/config6
4 files changed, 87 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 86f9f45..783b3cc 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,10 @@ install:
@cp lib/ssh-forcecommand ${lib_dir}
@chmod 755 ${lib_dir}/ssh-forcecommand
+test:
+ @prove
+
uninstall:
rm -f ${lib_dir}/ssh-forcecommand
-.PHONY: all install uninstall
+.PHONY: all install test uninstall
diff --git a/t/01-compile-pl.t b/t/01-compile-pl.t
new file mode 100755
index 0000000..661fbfb
--- /dev/null
+++ b/t/01-compile-pl.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('lib/ssh-forcecommand');
diff --git a/t/60-regression.t b/t/60-regression.t
new file mode 100644
index 0000000..8faa8c5
--- /dev/null
+++ b/t/60-regression.t
@@ -0,0 +1,69 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use 5.010;
+use Test::Command tests => (3 * 8);
+
+sub test_fc {
+ my (%conf) = @_;
+
+ $ENV{'SSH_ORIGINAL_COMMAND'} = $conf{'in'};
+
+ my $ret = $conf{'ret'} // 0;
+ my $out = ($conf{'out'} ? $conf{'out'} . "\n" : q{});
+ my $err = ($conf{'err'} ? $conf{'err'} . "\n" : q{});
+
+ my $cmd = Test::Command->new(cmd => 'lib/ssh-forcecommand t/config');
+
+ $cmd->stdout_is_eq($out);
+ $cmd->stderr_is_eq($err);
+
+ if ($ret == 0) {
+ $cmd->exit_is_num(0);
+ }
+ else {
+ $cmd->exit_isnt_num(0);
+ }
+}
+
+test_fc(
+ in => undef,
+ ret => 1,
+ err => 'No command',
+);
+
+test_fc(
+ in => 'invalid',
+ ret => 1,
+ err => 'Unknown command',
+);
+
+test_fc(
+ in => 'simple',
+ out => 'foo',
+);
+
+test_fc(
+ in => 'other',
+ out => 'bar',
+);
+
+test_fc(
+ in => 'nospace',
+ out => 'nospace!',
+);
+
+test_fc(
+ in => 'much space',
+ out => 'dude, lots of space',
+);
+
+test_fc(
+ in => 'spaceout',
+ out => 'space is beautiful',
+);
+
+test_fc(
+ in => 'equal',
+ out => 'foo = bar a=b',
+);
diff --git a/t/config b/t/config
new file mode 100644
index 0000000..b241979
--- /dev/null
+++ b/t/config
@@ -0,0 +1,6 @@
+simple = echo foo
+other = echo bar
+nospace=echo 'nospace!'
+much space = echo 'dude, lots of space'
+spaceout = echo 'space is beautiful'
+equal = echo foo = bar a=b