1#!/usr/local/bin/python3.8 2 3# Copyright 2012. Jurko Gospodnetic 4# Distributed under the Boost Software License, Version 1.0. 5# (See accompanying file LICENSE_1_0.txt or copy at 6# http://www.boost.org/LICENSE_1_0.txt) 7 8# Test Boost Jam parser's source line tracking & reporting. 9 10import BoostBuild 11 12 13def test_eof_in_string(): 14 t = BoostBuild.Tester(pass_toolset=False) 15 t.write("file.jam", '\n\n\naaa = "\n\n\n\n\n\n') 16 t.run_build_system(["-ffile.jam"], status=1) 17 t.expect_output_lines('file.jam:4: unmatched " in string at keyword =') 18 t.expect_output_lines("file.jam:4: syntax error at EOF") 19 t.cleanup() 20 21 22def test_error_missing_argument(eof): 23 """ 24 This use case used to cause a missing argument error to be reported in 25 module '(builtin)' in line -1 when the input file did not contain a 26 trailing newline. 27 28 """ 29 t = BoostBuild.Tester(pass_toolset=False) 30 t.write("file.jam", """\ 31rule f ( param ) { } 32f ;%s""" % __trailing_newline(eof)) 33 t.run_build_system(["-ffile.jam"], status=1) 34 t.expect_output_lines("file.jam:2: in module scope") 35 t.expect_output_lines("file.jam:1:see definition of rule 'f' being called") 36 t.cleanup() 37 38 39def test_error_syntax(eof): 40 t = BoostBuild.Tester(pass_toolset=False) 41 t.write("file.jam", "ECHO%s" % __trailing_newline(eof)) 42 t.run_build_system(["-ffile.jam"], status=1) 43 t.expect_output_lines("file.jam:1: syntax error at EOF") 44 t.cleanup() 45 46 47def test_traceback(): 48 t = BoostBuild.Tester(pass_toolset=False) 49 t.write("file.jam", """\ 50NOTFILE all ; 51ECHO [ BACKTRACE ] ;""") 52 t.run_build_system(["-ffile.jam"]) 53 t.expect_output_lines("file.jam 2 module scope") 54 t.cleanup() 55 56 57def __trailing_newline(eof): 58 """ 59 Helper function returning an empty string or a newling character to 60 append to the current output line depending on whether we want that line to 61 be the last line in the file (eof == True) or not (eof == False). 62 63 """ 64 if eof: 65 return "" 66 return "\n" 67 68 69test_error_missing_argument(eof=False) 70test_error_missing_argument(eof=True) 71test_error_syntax(eof=False) 72test_error_syntax(eof=True) 73test_traceback() 74test_eof_in_string() 75