diff --git a/share/test/aslint/test_check_files.py b/share/test/aslint/test_check_files.py index 5d4df03015a660c12493749d3c15436dd16ba924..e53c426966228016e867f927fa590eca4b38050c 100644 --- a/share/test/aslint/test_check_files.py +++ b/share/test/aslint/test_check_files.py @@ -6,12 +6,26 @@ Tests for the Docaster API. import os import os.path as osp +import tempfile import unittest from hamcrest import * from testutils import CODEASTER_SRC +# the parser fails in eval_parameters if 'if' statement is incomplete +SNIPPET_PARSER_ERROR = """ +subroutine rc32t + implicit none + character(len=8) :: option, poum + if (option .eq. 'RIGI_MECA_TANG') + poum = '-' + else + poum = '+' + endif +end subroutine +""" + def test_get_file_type(): """test manifest""" from aslint.filetype import get_file_type @@ -55,19 +69,24 @@ def test_filter_names(): assert len(filter_names(flist)) == 3 def test_check_files(): - """check a source file""" + """check source files""" from aslint.base_checkers import Report from aslint.check_files import check_files, read_waf_parameters from aslint.filetype import filter_arguments + from aslint.fortran.check_source import ParserMsg from aslint.logger import logger - args = ['bibc/supervis/aster_module.c', 'bibfor/utilifor/ibmain.F90'] + fname = tempfile.NamedTemporaryFile(suffix='.F90').name + with open(fname, 'w') as fort: + fort.write(SNIPPET_PARSER_ERROR) + + args = ['bibc/supervis/indik8.c', 'bibfor/utilifor/ibmain.F90', fname] args = [osp.join(CODEASTER_SRC, i) for i in args] filtered_args = filter_arguments(args, status='M') assert_that(filtered_args, has_key('c')) assert_that(filtered_args['c'], has_length(1)) assert_that(filtered_args, has_key('for')) - assert_that(filtered_args['for'], has_length(1)) + assert_that(filtered_args['for'], has_length(2)) wafc4che = osp.join(CODEASTER_SRC, 'build', 'std', 'c4che', 'release_cache.py') @@ -84,6 +103,10 @@ def test_check_files(): os.chdir(prev) logger.info(report.to_text()) + assert_that(report, has_key(fname)) + parser_error = [i for i in report[fname] if isinstance(i, ParserMsg)] + assert_that(parser_error, has_length(1)) + if __name__ == "__main__": import sys diff --git a/share/test/aslint/test_fortran_code.py b/share/test/aslint/test_fortran_code.py index 56d312aee6253e438c29478c758bc1a7d1015720..d0a318980dd6f3911520ac8436b66bd3ff054ba7 100644 --- a/share/test/aslint/test_fortran_code.py +++ b/share/test/aslint/test_fortran_code.py @@ -647,6 +647,15 @@ def test_long_assign(): lines = src.code_text().splitlines() assert len(lines) == 5, lines +def test_parser_error(): + """parser error""" + src = FC_source80(os.linesep.join([ + "if (cond.eq.1)", + " continue", + "endif" + ]), init_level=3) + assert_that(calling(src.code_text), raises(FC.FortranParserError)) + if __name__ == "__main__": import sys