diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2018-08-10 10:38:32 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-08-10 11:50:45 -0700 |
commit | c4cafcecb1f50e38275b7d82852fd33b63964fb2 (patch) | |
tree | 421842c344d27873bcf3ce9f458a6f0c27a4315f /tools/util.py | |
parent | e28d7abc1c369185cc9d1deb4891c6004d9d7ad7 (diff) |
Support wildcard matching of output in tests
Diffstat (limited to 'tools/util.py')
-rw-r--r-- | tools/util.py | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/tools/util.py b/tools/util.py index 0a6f6a071..9e29cf742 100644 --- a/tools/util.py +++ b/tools/util.py @@ -1,5 +1,4 @@ -# Copyright 2018 Ryan Dahl <ry@tinyclouds.org> -# All rights reserved. MIT License. +# Copyright 2018 the Deno authors. All rights reserved. MIT license. import os import shutil import stat @@ -133,3 +132,33 @@ def build_path(): return os.environ["DENO_BUILD_PATH"] else: return os.path.join(root_path, "out", build_mode()) + + +# Returns True if the expected matches the actual output, allowing variation +# from actual where expected has the wildcard (e.g. matches /.*/) +def pattern_match(pattern, string, wildcard="[WILDCARD]"): + if len(pattern) == 0: + return string == 0 + if pattern == wildcard: + return True + + parts = str.split(pattern, wildcard) + + if len(parts) == 1: + return pattern == string + + if string.startswith(parts[0]): + string = string[len(parts[0]):] + else: + return False + + for i in range(1, len(parts)): + if i == (len(parts) - 1): + if parts[i] == "" or parts[i] == "\n": + return True + found = string.find(parts[i]) + if found < 0: + return False + string = string[(found + len(parts[i])):] + + return len(string) == 0 |