Skip to content

Commit

Permalink
Implement strict attribute for challenges.
Browse files Browse the repository at this point in the history
This way is possible to toggle equality check for empty lines.
  • Loading branch information
Giuseppe .* 破 committed Mar 27, 2017
1 parent 18cd722 commit 90a41e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions bin/docker_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions challenges.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
# author: Add a field for contributions.
- slug: hello_world
version: 3
Expand Down Expand Up @@ -419,6 +420,7 @@
- ''
- '# **************'
- '# Reverse the README'
strict: true
- slug: remove_duplicate_lines
version: 3
author: cmdchallenge
Expand Down

0 comments on commit 90a41e4

Please sign in to comment.