Permalink
Browse files

Make the unit tests insensitive to the presence of fastlex.so.

  • Loading branch information...
Andy Chu
Andy Chu committed Jun 1, 2018
1 parent 9995c96 commit 1b5e27948f892463bf080852f02e7da91c58ae9a
Showing with 14 additions and 15 deletions.
  1. +11 −13 osh/lex_test.py
  2. +1 −2 osh/match.py
  3. +2 −0 test/unit.sh
View
@@ -4,15 +4,16 @@
lex_test.py: Tests for lex.py
"""
import re
import unittest
from core.lexer import LineLexer
from core import test_lib
from osh import lex
from osh import match
from osh import parse_lib
from osh.meta import ast, Id, Kind, LookupKind, types
from osh.lex import LEXER_DEF
lex_mode_e = types.lex_mode_e
@@ -227,21 +228,18 @@ def testLookAhead(self):
ast.token(Id.Op_LParen, '('), l.LookAhead(lex_mode_e.OUTER))
OUTER_RE = match._CompileAll(LEXER_DEF[lex_mode_e.OUTER])
DOUBLE_QUOTED_RE = match._CompileAll(LEXER_DEF[lex_mode_e.DQ])
class RegexTest(unittest.TestCase):
def testOuter(self):
o = OUTER_RE
nul_pat, _ = o[3]
print(nul_pat.match('\0'))
def testNul(self):
nul_pat = re.compile(r'[\0]')
self.assertEqual(False, bool(nul_pat.match('x')))
self.assertEqual(True, bool(nul_pat.match('\0')))
def testDoubleQuoted(self):
d = DOUBLE_QUOTED_RE
nul_pat, _ = d[3]
print(nul_pat.match('\0'))
_, p, _ = lex.ECHO_E_DEF[-1]
print('P %r' % p)
last_echo_e_pat = re.compile(p)
self.assertEqual(True, bool(last_echo_e_pat.match('x')))
self.assertEqual(False, bool(last_echo_e_pat.match('\0')))
class EchoLexerTest(unittest.TestCase):
View
@@ -19,8 +19,7 @@
except ImportError:
fastlex = None
#if fastlex:
if 0:
if fastlex:
re = None # Shouldn't use re module in this case
else:
import re
View
@@ -69,6 +69,8 @@ run-test-and-maybe-abort() {
}
all() {
# For testing
#export FASTLEX=0
time tests-to-run | xargs -n 1 -- $0 run-test-and-maybe-abort
echo
echo "All unit tests passed."

0 comments on commit 1b5e279

Please sign in to comment.