diff options
author | Matthias Paulmier <matthias.paulmier@etu.u-bordeaux.fr> | 2018-06-12 18:00:35 +0200 |
---|---|---|
committer | Matthias Paulmier <matthias.paulmier@etu.u-bordeaux.fr> | 2018-06-22 14:19:18 +0200 |
commit | 43f7827ed147ec17a4995421cf21e7180784b1a9 (patch) | |
tree | 12e02a9a62a3ec33e7351fc7a61df25c481be8bc | |
parent | 8e69f70005326c0dd5e499869b72ffc1ecce7f71 (diff) | |
download | automake-43f7827ed147ec17a4995421cf21e7180784b1a9.tar.gz |
t: Add a test for the CondStack module
This tests that the &cond_stack_* methods assure the good balance of the
conditional stack.
* CondStack.pl: New test for the CondStack module.
-rw-r--r-- | t/list-of-tests.mk | 1 | ||||
-rw-r--r-- | t/pm/CondStack.pl | 76 |
2 files changed, 77 insertions, 0 deletions
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk index 5c49a244e..63ea87701 100644 --- a/t/list-of-tests.mk +++ b/t/list-of-tests.mk @@ -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 index 000000000..5e28e69ae --- /dev/null +++ b/t/pm/CondStack.pl @@ -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); |