]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
t: Add a test for the CondStack module
authorMatthias Paulmier <matthias.paulmier@etu.u-bordeaux.fr>
Tue, 12 Jun 2018 16:00:35 +0000 (18:00 +0200)
committerMatthias Paulmier <matthias.paulmier@etu.u-bordeaux.fr>
Fri, 22 Jun 2018 12:19:18 +0000 (14:19 +0200)
This tests that the &cond_stack_* methods assure the good balance of the
conditional stack.

* CondStack.pl: New test for the CondStack module.

t/list-of-tests.mk
t/pm/CondStack.pl [new file with mode: 0644]

index 5c49a244e00d49715a4e268a4f5b3d13d425af92..63ea87701729e7c1f1ba87d46e9102420161c4a7 100644 (file)
@@ -50,6 +50,7 @@ t/pm/Cond2.pl \
 t/pm/Cond3.pl \
 t/pm/Condition.pl \
 t/pm/Condition-t.pl \
+t/pm/CondStack.pl \
 t/pm/DisjCon2.pl \
 t/pm/DisjCon3.pl \
 t/pm/DisjConditions.pl \
diff --git a/t/pm/CondStack.pl b/t/pm/CondStack.pl
new file mode 100644 (file)
index 0000000..5e28e69
--- /dev/null
@@ -0,0 +1,76 @@
+# Copyright (C) 2018  Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use Automake::CondStack;
+use Automake::Condition qw (TRUE FALSE);
+use Automake::Location;
+
+# The different test cases.  What happens with IF alone?
+my @tests = (['IF', 'ELSE', 'ENDIF'],
+            ['ELSE', 'ENDIF'],
+            ['IF', 'ENDIF'],
+            ['ENDIF'],
+            ['IF', 'ELSE', 'IF', 'ELSE', 'ENDIF']);
+
+my @exp_res = (0, 1, 0, 1, 0);
+
+my $where = new Automake::Location "/dev/null:0";
+
+sub test_cond_stack ()
+{
+  my @real_res = ();
+  for (@tests)
+    {
+      # Reset conditional stack for each test case
+      @cond_stack = ();
+      my $res = 0;
+      my $else_called = 0;
+      for my $test (@$_)
+        {
+         if ($test eq 'IF')
+           {
+             cond_stack_if (undef, 'FALSE', $where);
+           }
+         if ($test eq 'ELSE')
+            {
+              $else_called = 1;
+             if (cond_stack_else ('!', 'FALSE', $where) == FALSE)
+               {
+                 $res = 1;
+                 last;
+               }
+           }
+         if ($test eq 'ENDIF')
+            {
+              my $cond = ($else_called ? TRUE : FALSE);
+             if (cond_stack_else (undef, undef, $where) == $cond)
+                {
+                 $res = 1;
+                 last;
+               }
+           }
+        }
+      push @real_res, $res;
+    }
+  print "@real_res\n";
+  print "@exp_res\n";
+  for my $i (0 .. $#exp_res)
+    {
+      return 1 if $real_res[$i] ne $exp_res[$i];
+    }
+  return 0;
+}
+
+exit (test_cond_stack);