From 0fdd80f4871102f7f6312ffa84cc2e490b2df09d Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Sat, 10 Mar 2012 18:57:04 +0530 Subject: [PATCH] (tests) added a module test for explode plus a helper function to Test.pm (helps while developing tests) --- src/Gitolite/Test.pm | 8 ++++ t/m-explode.t | 102 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100755 t/m-explode.t diff --git a/src/Gitolite/Test.pm b/src/Gitolite/Test.pm index dcaf3fe..8251c41 100644 --- a/src/Gitolite/Test.pm +++ b/src/Gitolite/Test.pm @@ -8,6 +8,7 @@ package Gitolite::Test; try put text + dump ); #>>> use Exporter 'import'; @@ -43,4 +44,11 @@ try " gitolite setup -a admin " or die "could not setup the test environment; errors:\n\n" . text() . "\n\n"; +sub dump { + use Data::Dumper; + for my $i (@_) { + print STDERR "DBG: " . Dumper($i); + } +} + 1; diff --git a/t/m-explode.t b/t/m-explode.t new file mode 100755 index 0000000..aef337f --- /dev/null +++ b/t/m-explode.t @@ -0,0 +1,102 @@ +#!/usr/bin/perl +use strict; +use warnings; +use 5.10.0; + +use Test; +BEGIN { plan tests => + 2 +} + +use lib "$ENV{PWD}/src"; +use Gitolite::Test; +use Gitolite::Conf::Explode; + +my @out; +my @out2; + +warn " + <<< expect a couple of warnings about already included files >>> +"; + +# test 1 -- space normalisation + + put "foo", " + foo line 1 + foo=line 2 + + + foo 3 + "; + @out = (); + explode("foo", 'master', \@out); + @out2 = ( + 'foo line 1', + 'foo = line 2', + 'foo 3', + ); + + ok(@out ~~ @out2); + +# test 2 -- include/subconf processing + + put "foo", " + foo line 1 + \@fog=line 2 + include \"bar.conf\" + + foo line=5 + subconf \"subs/baz.conf\" + include \"bar.conf\" + foo line=7 + include \"bazup.conf\" + "; + + put "bar.conf", " + \@brg=line 1 + + bar line 3 + "; + + mkdir("subs"); + + put "subs/baz.conf", " + \@bzg = line 1 + + include \"subs/baz2.conf\" + + baz=line 3 + "; + + put "subs/baz2.conf", " + baz2 line 1 + baz2 line 2 + include \"bazup.conf\" + baz2 line 4 + "; + + put "bazup.conf", " + whatever... + "; + + @out = (); + explode("foo", 'master', \@out); + + @out2 = ( + 'foo line 1', + '@fog = line 2', + '@brg = line 1', + 'bar line 3', + 'foo line = 5', + 'subconf baz', + '@baz.bzg = line 1', + 'baz2 line 1', + 'baz2 line 2', + 'whatever...', + 'baz2 line 4', + 'baz = line 3', + 'subconf master', + 'foo line = 7' + ); + + ok(@out ~~ @out2);