summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJoachim Breitner <mail@joachim-breitner.de>2009-06-13 22:54:49 +0200
committerRaphael Hertzog <hertzog@debian.org>2009-06-20 22:34:28 +0200
commit38b79ccbca7460f0f39daf5baa1d7036464f5b0d (patch)
treedda611e5fadc5d6bd14ae21f9b0287812e7b1b8d /scripts
parentbf4582423b44556f05744e7633d7d56a75fc77c9 (diff)
downloaddpkg-38b79ccbca7460f0f39daf5baa1d7036464f5b0d.tar.gz
Dpkg::Substvars: add non-regression test suite
Diffstat (limited to 'scripts')
-rw-r--r--scripts/t/750_Dpkg_Substvars.t74
-rw-r--r--scripts/t/750_Dpkg_Substvars/substvars19
2 files changed, 83 insertions, 0 deletions
diff --git a/scripts/t/750_Dpkg_Substvars.t b/scripts/t/750_Dpkg_Substvars.t
new file mode 100644
index 000000000..056d83dc1
--- /dev/null
+++ b/scripts/t/750_Dpkg_Substvars.t
@@ -0,0 +1,74 @@
+# -*- mode: cperl;-*-
+
+use Test::More tests => 24;
+
+use strict;
+use warnings;
+
+use Dpkg qw($version);
+use Dpkg::Arch qw(get_host_arch);
+
+use_ok('Dpkg::Substvars');
+
+my $srcdir = $ENV{srcdir} || '.';
+$srcdir .= '/t/750_Dpkg_Substvars';
+
+my $s = Dpkg::Substvars->new();
+
+$s->parse("$srcdir/substvars1");
+
+# simple value tests
+is($s->get('var1'), 'Some value', 'var1');
+is($s->get('var2'), 'Some other value', 'var2');
+is($s->get('var3'), 'Yet another value', 'var3');
+is($s->get('var4'), undef, 'no var4');
+
+# overriding
+$s->set('var1', 'New value');
+is($s->get('var1'), 'New value','var1 updated');
+
+# deleting
+$s->delete('var3');
+is($s->get('var3'), undef, 'var3 deleted');
+
+# default variables
+is($s->get('Newline'), "\n", 'newline');
+is($s->get('Space'), " ", 'space');
+is($s->get('Tab'), "\t", 'tab');
+is($s->get('dpkg:Version'), $version, 'dpkg version 1');
+
+# special variables
+is($s->get('Arch'), undef, 'no arch');
+$s->set_arch_substvars();
+is($s->get('Arch'), get_host_arch(),'arch');
+
+is($s->get($_), undef, 'no ' . $_) for qw/binary:Version source:Version source:Upstream-Version/;
+$s->set_version_substvars("1:2.3.4~5-6.7.8~nmu9+b0");
+is($s->get("binary:Version"), "1:2.3.4~5-6.7.8~nmu9+b0", "binary:Version");
+is($s->get("source:Version"), "1:2.3.4~5-6.7.8~nmu9", "source:Version");
+is($s->get("source:Upstream-Version"), "1:2.3.4~5", "source:Upstream-Version");
+
+# Replace stuff
+is($s->substvars('This is a string ${var1} with variables ${binary:Version}'),
+ "This is a string New value with variables 1:2.3.4~5-6.7.8~nmu9+b0",
+ "substvars simple");
+
+my $output;
+$SIG{'__WARN__'} = sub { $output .= $_[0] };
+is($s->substvars('This is a string with unknown variable ${blubb}'),
+ "This is a string with unknown variable ",
+ "substvars missing");
+delete $SIG{'__WARN__'};
+is($output, '750_Dpkg_Substvars.t: warning: unknown substitution variable ${blubb}'."\n"
+ , 'missing variables warning');
+
+# Recursive replace
+$s->set("rvar", 'recursive ${var1}');
+is($s->substvars('This is a string with ${rvar}'),
+ "This is a string with recursive New value",
+ "substvars recursive");
+
+# Strange input
+is($s->substvars('Nothing to $ ${substitute here}, is it ${}?, it ${is'),
+ 'Nothing to $ ${substitute here}, is it ${}?, it ${is',
+ "substvars strange");
diff --git a/scripts/t/750_Dpkg_Substvars/substvars1 b/scripts/t/750_Dpkg_Substvars/substvars1
new file mode 100644
index 000000000..f71c95361
--- /dev/null
+++ b/scripts/t/750_Dpkg_Substvars/substvars1
@@ -0,0 +1,9 @@
+var1=Some value
+var2=Some other value
+# the next line is empty
+
+# the next line has some spaces
+
+ # this line has a late comment
+var3=Yet another value
+#var4=This is not set