From 08c15a105aef04b8db7d34a8a53b0f7132b94d79 Mon Sep 17 00:00:00 2001 From: Jun Wu Date: Wed, 17 Jul 2019 20:59:57 -0700 Subject: [PATCH] testutil/dott: normalize error messages Summary: run-tests.py uses common-pattern.py to normalize error messages to things like `$ENOENT$`. Implement that behavior. Reviewed By: xavierd Differential Revision: D16209208 fbshipit-source-id: 3e609cc16442f80b844264f93dce9ea46517458d --- tests/testutil/dott/shobj.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/testutil/dott/shobj.py b/tests/testutil/dott/shobj.py index ee623cdbb0..241e40daf1 100644 --- a/tests/testutil/dott/shobj.py +++ b/tests/testutil/dott/shobj.py @@ -157,3 +157,28 @@ _normalizefuncs = [] # Decorator. Add an output normalizing function. normalizeoutput = _normalizefuncs.append + + +_errors = { + br"$ENOENT$": ( + # strerror() + br"No such file or directory", + # FormatMessage(ERROR_FILE_NOT_FOUND) + br"The system cannot find the file specified", + ), + br"$ENOTDIR$": ( + # strerror() + br"Not a directory", + # FormatMessage(ERROR_PATH_NOT_FOUND) + br"The system cannot find the path specified", + ), +} + + +@normalizeoutput +def _normalizeerr(out, _errors=_errors): + """Translate error messages to '$ENOENT$'""" + for name, values in _errors.items(): + for value in values: + out = out.replace(value, name) + return out