tests: Fix a deeper bug in null byte check in testsuite.
[pspp] / tests / language / lexer / lexer.at
index 2c1dfc93b850d01446692dfa48425292ead089d2..bd960710c47686a3ade9a2a02715dbef06829691 100644 (file)
@@ -18,3 +18,66 @@ a
 2.00
 ])
 AT_CLEANUP
+
+AT_SETUP([lexer properly reports scan errors])
+AT_DATA([lexer.sps], [dnl
+x'123'
+x'1x'
+u''
+u'012345678'
+u'd800'
+u'110000'
+'foo
+'very long unterminated string that be ellipsized in its error message
+1e .x
+`
+�
+])
+AT_CHECK([pspp -O format=csv lexer.sps], [1], [dnl
+"lexer.sps:1.1-1.6: error: Syntax error at `x'123'': String of hex digits has 3 characters, which is not a multiple of 2."
+
+lexer.sps:2.1-2.5: error: Syntax error at `x'1x'': `x' is not a valid hex digit.
+
+"lexer.sps:3.1-3.3: error: Syntax error at `u''': Unicode string contains 0 bytes, which is not in the valid range of 1 to 8 bytes."
+
+"lexer.sps:4.1-4.12: error: Syntax error at `u'012345678'': Unicode string contains 9 bytes, which is not in the valid range of 1 to 8 bytes."
+
+lexer.sps:5.1-5.7: error: Syntax error at `u'd800'': U+D800 is not a valid Unicode code point.
+
+lexer.sps:6.1-6.9: error: Syntax error at `u'110000'': U+110000 is not a valid Unicode code point.
+
+lexer.sps:7.1-7.4: error: Syntax error at `'foo': Unterminated string constant.
+
+lexer.sps:8.1-8.70: error: Syntax error at `'very long unterminated string that be ellipsized in its err...': Unterminated string constant.
+
+lexer.sps:9.1-9.2: error: Syntax error at `1e': Missing exponent following `1e'.
+
+lexer.sps:9.4: error: Syntax error at `.': Unexpected `.' in middle of command.
+
+lexer.sps:9: error: Unknown command `x'.
+
+lexer.sps:10.1: error: Syntax error at ``': Bad character ``' in input.
+
+lexer.sps:11.1: error: Syntax error at `�': Bad character U+FFFD in input.
+])
+AT_CLEANUP
+
+# Bug #47602.
+AT_SETUP([lexer crash due to null byte])
+# Intentionally leave out the new-line and add a null byte:
+printf "datA dist list notable file='input.txt'/a b c.
+lis|.\0" > lexer.sps
+
+# We sort the output into a predictable order because the lexer finds
+# and reports null bytes as soon as it reads them into its input
+# buffer, as opposed to when it encounters them during tokenization.
+# This also means that null bytes might be reported as part of one
+# command or another or none, hence removing the LIST: prefix.
+AT_CHECK([pspp -O format=csv lexer.sps > lexer.csv], [1])
+AT_CHECK([sed '/^$/d
+s/LIST: //' lexer.csv | sort], [0], [dnl
+lexer.sps: error: Bad character U+0000 in input.
+lexer.sps:1: error: Unknown command `datA dist'.
+lexer.sps:2: error: LIST is allowed only after the active dataset has been defined.
+])
+AT_CLEANUP