From 6758100e6eb7de0e5b8044fc50ddefad76c0a77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giuseppe=20=2E*=20=E7=A0=B4?= Date: Mon, 27 Mar 2017 02:45:47 +0200 Subject: [PATCH] Implement `strict` attribute for challenges. This way is possible to toggle equality check for empty lines. --- bin/docker_cmd.py | 10 ++++++++-- challenges.yaml | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/docker_cmd.py b/bin/docker_cmd.py index fe29f79ca..d5209aaff 100644 --- a/bin/docker_cmd.py +++ b/bin/docker_cmd.py @@ -45,6 +45,13 @@ def __exit__(self, type, value, traceback): signal.alarm(0) +def strip_output(output, challenge, script_name, return_token): + strict = 'expected_output' in challenge and 'strict' in challenge['expected_output'] + if not strict: output = re.sub(r'\n{2,}', '\n', output).rstrip() + output = re.sub(r'{}\d+'.format(return_token), '', output).rstrip() + output = re.sub(r'/tmp/.{}: line \d+: (.*)'.format(script_name), r'\1', output) + return output + def output_from_cmd(cmd, challenge, docker_version=None, docker_base_url=None, tls_settings=None): if tls_settings: tls_config = docker.tls.TLSConfig(**tls_settings) @@ -92,8 +99,7 @@ def output_from_cmd(cmd, challenge, docker_version=None, docker_base_url=None, t if return_code_match is None: raise DockerValidationError("Unable to determine return code from command") return_code = int(return_code_match.group(1)) - output = re.sub(r'{}\d+'.format(return_token), '', output).rstrip() - output = re.sub(r'/tmp/.{}: line \d+: (.*)'.format(script_name), r'\1', output) + output = strip_output(output, challenge, script_name, return_token) if return_code == 124: output += "\n** Command timed out after {} seconds **".format(CMD_TIMEOUT) if 'tests' in challenge: diff --git a/challenges.yaml b/challenges.yaml index 2ed3fcf74..8c52608b5 100644 --- a/challenges.yaml +++ b/challenges.yaml @@ -10,6 +10,7 @@ # tests: tests to run after the command completes # version: if the challenge is modified this number should be bumped # refresh the cache. +# strict: empty lines must NOT be ignored (defaults to false) # author: Add a field for contributions. - slug: hello_world version: 3 @@ -419,6 +420,7 @@ - '' - '# **************' - '# Reverse the README' + strict: true - slug: remove_duplicate_lines version: 3 author: cmdchallenge