diff options
Diffstat (limited to 't')
-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); |