quilt-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Quilt-dev] [PATCH 2/3] test/run: Fix variable substitution


From: Jean Delvare
Subject: [Quilt-dev] [PATCH 2/3] test/run: Fix variable substitution
Date: Wed, 18 Dec 2013 14:17:09 +0100

Variable substitution on command lines was happening too early so
setting a variable only took effect with the second next line of the
test case.

Additionally, there was no check that the environment variable was
actually set. This resulted in perl warnings during the test suite if
a variable is ever used before having been set.

Fix both issues.

Also add a test case for this feature, to avoid a future breakage.
Some of the tester script features are tricky and easy to get wrong,
so test them independently of quilt in a dedicated test case.
---
 test/run         |   16 +++++++++++-----
 test/tester.test |   25 +++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 5 deletions(-)

--- a/test/run
+++ b/test/run
@@ -81,18 +81,24 @@ if (defined $ARGV[0]) {
        *SOURCE = *STDIN;
 }
 
+# Substitute %{VAR} with environment variables
+sub substitute_vars($)
+{
+       my ($line) = @_;
+       $line =~ s[%{(\w+)}][defined $ENV{$1} ? $ENV{$1} : ""]eg;
+       return $line;
+}
+
 while (defined(my $line = <SOURCE>)) {
        $lineno++;
-       # Substitute %{VAR} with environment variables
-       $line =~ s[%{(\w+)}][$ENV{$1}]eg;
 
        # Collect input and output for the previous command
        if ($line =~ s/^\s*< ?//) {
-               push @$in, $line;
+               push @$in, substitute_vars($line);
                next;
        }
        if ($line =~ s/^\s*> ?//) {
-               push @$out, $line;
+               push @$out, substitute_vars($line);
                next;
        }
 
@@ -108,7 +114,7 @@ while (defined(my $line = <SOURCE>)) {
                # Substitute %{?} with the last command's status
                $line =~ s[%{\?}][$last_status]eg;
 
-               $prog = [ map { s/\\(.)/$1/g; $_ } split /(?<!\\)\s+/, $line ];
+               $prog = [ map { s/\\(.)/$1/g; $_ } split /(?<!\\)\s+/, 
substitute_vars($line) ];
                $prog_line = $lineno;
                $in = [];
                $out = [];
--- /dev/null
+++ b/test/tester.test
@@ -0,0 +1,25 @@
+# Test the testing code itself
+
+# Exported variables should be available immediately after being set
+$ echo %{VAR}
+>
+$ export VAR=foo
+$ echo %{VAR}
+> foo
+$ export VAR=bar
+$ echo %{VAR}
+> bar
+
+# Exported variables should survive accross commands and comments
+$ true
+$ echo %{VAR}
+> bar
+
+# Test multiple use cases
+$ echo "A %{VAR}%{VAR}ian walks into a %{VAR}"
+> A barbarian walks into a bar
+
+# Test combined use and set
+$ export PLACE=%{VAR}racks
+$ echo %{PLACE}
+> barracks

-- 
Jean Delvare
Suse L3 Support




reply via email to

[Prev in Thread] Current Thread [Next in Thread]