Permalink
Browse files

Change unit test output to plain text.

We are publishing output directly on the web, so these should be plain
text.

- core/braces_test.py: Don't print ANSI escape sequences.
- core/lexer_gen_test.py: Remove unprintable output.
  • Loading branch information...
Andy Chu
Andy Chu committed Jul 10, 2018
1 parent ce50443 commit b8a7955d434aea10a95968c0e6f4407e2f770679
Showing with 18 additions and 8 deletions.
  1. +7 −7 core/braces_test.py
  2. +2 −1 core/lexer_gen_test.py
  3. +9 −0 core/test_lib.py
View
@@ -19,9 +19,9 @@ def _assertReadWord(*args):
return word_parse_test._assertReadWord(*args)
def _ColorPrint(n):
def _PrettyPrint(n):
from asdl import format as fmt
ast_f = fmt.AnsiOutput(sys.stdout)
ast_f = fmt.DetectConsoleOutput(sys.stdout)
tree = fmt.MakeTree(n)
fmt.PrintTree(tree, ast_f)
@@ -85,7 +85,7 @@ def testBraceDetect(self):
self.assertEqual(3, len(middle_part.words)) # a ={b,c}= d
first_alternative = middle_part.words[0]
_ColorPrint(first_alternative)
_PrettyPrint(first_alternative)
self.assertEqual(1, len(first_alternative.parts)) # a
#print('!!', first_alternative)
@@ -108,7 +108,7 @@ def testBraceExpand(self):
results = braces._BraceExpand(w.parts)
self.assertEqual(1, len(results))
for parts in results:
_ColorPrint(ast.CompoundWord(parts))
_PrettyPrint(ast.CompoundWord(parts))
print('')
w = _assertReadWord(self, 'B-{a,b}-E')
@@ -119,7 +119,7 @@ def testBraceExpand(self):
results = braces._BraceExpand(tree.parts)
self.assertEqual(2, len(results))
for parts in results:
_ColorPrint(ast.CompoundWord(parts))
_PrettyPrint(ast.CompoundWord(parts))
print('')
w = _assertReadWord(self, 'B-{a,={b,c,d}=,e}-E')
@@ -130,7 +130,7 @@ def testBraceExpand(self):
results = braces._BraceExpand(tree.parts)
self.assertEqual(5, len(results))
for parts in results:
_ColorPrint(ast.CompoundWord(parts))
_PrettyPrint(ast.CompoundWord(parts))
print('')
w = _assertReadWord(self, 'B-{a,b}-{c,d}-E')
@@ -141,7 +141,7 @@ def testBraceExpand(self):
results = braces._BraceExpand(tree.parts)
self.assertEqual(4, len(results))
for parts in results:
_ColorPrint(ast.CompoundWord(parts))
_PrettyPrint(ast.CompoundWord(parts))
print('')
View
@@ -7,6 +7,7 @@
import unittest
from core import lexer_gen # module under test
from core import test_lib
class LexerGenTest(unittest.TestCase):
@@ -38,7 +39,7 @@ def testTranslateRegex(self):
]
for py, expected in PAIRS:
#self.assertEqual(expected, lexer_gen.TranslateRegex(py))
print('---', py)
print('--- %s' % test_lib.PrintableString(py))
actual = lexer_gen.TranslateRegex(py)
print(repr(actual))
self.assertEqual(expected, actual)
View
@@ -9,11 +9,20 @@
test_lib.py - Functions for testing.
"""
import string
from core import alloc
from osh.meta import Id
from asdl import py_meta
def PrintableString(s):
"""For pretty-printing in tests."""
if all(c in string.printable for c in s):
return s
return repr(s)
def TokensEqual(left, right):
# Ignoring location in CompoundObj.__eq__ now, but we might want this later.
return left.id == right.id and left.val == right.val

0 comments on commit b8a7955

Please sign in to comment.