aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2018-05-21 09:02:26 -0700
committerGerald Combs <gerald@wireshark.org>2018-05-21 18:03:42 +0000
commit2ecf69f7731083f5d8e3765fe1965a8a8cb11d9c (patch)
tree7facdf43b1206698688fe63a146d4d74f4306b5d /test
parente6c832c49a66dc88b305574d8875eb811a58124e (diff)
Test: Be more paranoid about our log output.
Run our CTest tests with PYTHONIOENCODING=UTF-8. If someone runs our tests manually and their output encoding isn't UTF-8, print replacement characters instead of failing with an error. Open our log files with "errors='backslashreplace'" in case their contents aren't UTF-8. Change-Id: Ifa4d12c2b5e272cf3903f3e0c6102e4d961562f1 Reviewed-on: https://code.wireshark.org/review/27686 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'test')
-rw-r--r--test/subprocesstest.py2
-rwxr-xr-xtest/test.py12
2 files changed, 13 insertions, 1 deletions
diff --git a/test/subprocesstest.py b/test/subprocesstest.py
index 61bab5f970..8fae5da038 100644
--- a/test/subprocesstest.py
+++ b/test/subprocesstest.py
@@ -182,7 +182,7 @@ class SubprocessTestCase(unittest.TestCase):
# Leave some evidence behind.
self.cleanup_files = []
print('\nProcess output for {}:'.format(self.id()))
- with io.open(self.log_fname, 'r', encoding='UTF-8') as log_fd:
+ with io.open(self.log_fname, 'r', encoding='UTF-8', errors='backslashreplace') as log_fd:
for line in log_fd:
sys.stdout.write(line)
for filename in self.cleanup_files:
diff --git a/test/test.py b/test/test.py
index 91bddaa5f8..cc6c134e30 100755
--- a/test/test.py
+++ b/test/test.py
@@ -112,6 +112,18 @@ def main():
parser.print_usage()
sys.exit(1)
+ #
+ if sys.stdout.encoding != 'UTF-8':
+ import codecs
+ import locale
+ sys.stderr.write('Warning: Output encoding is {0} and not UTF-8.\n'.format(sys.stdout.encoding))
+ if sys.version_info[0] >= 3:
+ sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout.buffer, 'backslashreplace')
+ sys.stderr = codecs.getwriter(locale.getpreferredencoding())(sys.stderr.buffer, 'backslashreplace')
+ else:
+ sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout, 'backslashreplace')
+ sys.stderr = codecs.getwriter(locale.getpreferredencoding())(sys.stderr, 'backslashreplace')
+
run_suite = unittest.defaultTestLoader.loadTestsFromNames(run_ids)
runner = unittest.TextTestRunner(verbosity=args.verbose)
test_result = runner.run(run_suite)