From 527c802511d821d0e204ec4031344f742786d9f9 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Fri, 19 Jan 2018 21:19:36 +0100 Subject: [PATCH] more coverage * python/spot/impl.i: Add missing bindings from remprop.hh * tests/python/except.py: New file to test several error cases. * tests/Makefile.am: Add it. * spot/twaalgos/rabin2parity.cc (iar): Fix error message. --- python/spot/impl.i | 2 ++ spot/twaalgos/rabin2parity.cc | 10 ++---- tests/Makefile.am | 1 + tests/python/except.py | 61 +++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 tests/python/except.py diff --git a/python/spot/impl.i b/python/spot/impl.i index 1f200cd1e..54cbb631e 100644 --- a/python/spot/impl.i +++ b/python/spot/impl.i @@ -138,6 +138,7 @@ #include #include #include +#include #include #include #include @@ -579,6 +580,7 @@ def state_is_accepting(self, src) -> "bool": %include %include %include +%include %include %include %traits_swigtype(spot::scc_info_node); diff --git a/spot/twaalgos/rabin2parity.cc b/spot/twaalgos/rabin2parity.cc index 0847803dc..71d843c94 100644 --- a/spot/twaalgos/rabin2parity.cc +++ b/spot/twaalgos/rabin2parity.cc @@ -282,12 +282,8 @@ namespace spot twa_graph_ptr iar(const const_twa_graph_ptr& aut) { - auto res = iar_maybe(aut); - if (!res) - throw std::runtime_error("rabin2parity works only for Rabin-like " - "automata"); - - return res; + if (auto res = iar_maybe(aut)) + return res; + throw std::runtime_error("iar() expects Rabin-like input"); } } - diff --git a/tests/Makefile.am b/tests/Makefile.am index 7622c69b8..5c4f4b1ba 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -361,6 +361,7 @@ TESTS_python = \ python/declenv.py \ python/decompose_scc.py \ python/dualize.py \ + python/except.py \ python/gen.py \ python/implies.py \ python/interdep.py \ diff --git a/tests/python/except.py b/tests/python/except.py new file mode 100644 index 000000000..8ed74639e --- /dev/null +++ b/tests/python/except.py @@ -0,0 +1,61 @@ +# -*- mode: python; coding: utf-8 -*- +# Copyright (C) 2018 Laboratoire de Recherche et Développement de +# l'Epita (LRDE). +# +# This file is part of Spot, a model checking library. +# +# Spot 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 3 of the License, or +# (at your option) any later version. +# +# Spot 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 . + + +# Test some function that must return exceptions on error. Doing +# so is mostly a way to improve the coverage report. + + +import spot + +try: + spot.iar(spot.translate('GFa & GFb & GFc')) +except RuntimeError as e: + assert 'iar() expects Rabin-like input' in str(e) + +alt = spot.dualize(spot.translate('FGa | FGb')) + +try: + spot.tgba_determinize(alt) +except RuntimeError as e: + assert 'tgba_determinize() does not support alternation' in str(e) + + +aut = spot.translate('a U b U c') +aps = aut.ap() +rem = spot.remove_ap() +rem.add_ap('"a"=0,b') +aut = rem.strip(aut) +assert aut.ap() == aps[2:] +try: + rem.add_ap('"a=0,b') +except ValueError as e: + assert """missing closing '"'""" in str(e) + +try: + rem.add_ap('a=0=b') +except ValueError as e: + assert """unexpected '=' at position 3""" in str(e) + + +si = spot.scc_info(alt) +try: + si.determine_unknown_acceptance() +except RuntimeError as e: + assert "scc_info::determine_unknown_acceptance() does not supp" in str(e)