Skip to content

Commit

Permalink
Add epicbox-hyperskill/go image (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Turov authored Jun 16, 2021
1 parent 1c8f891 commit 7c4bc4d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
9 changes: 9 additions & 0 deletions epicbox-hyperskill/go/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golang:1.16.5-buster

RUN apt-get update && \
apt-get install -y python3 python3-pip && \
rm -rf /var/lib/apt/lists/*

RUN pip3 install https://github.com/hyperskill/hs-test-python/archive/v5.tar.gz

COPY checker/ /checker/
6 changes: 6 additions & 0 deletions epicbox-hyperskill/go/checker/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cd /sandbox
python3 tests.py --inside_docker > stdout.txt 2> stderr.txt
echo $? > code.txt
python3 /checker/process.py
42 changes: 42 additions & 0 deletions epicbox-hyperskill/go/checker/process.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import json

FAILED_TEST_BEGIN = '#educational_plugin FAILED + '
FAILED_TEST_CONTINUE = '#educational_plugin '

if __name__ == '__main__':
score = 1
feedback = ''

code = open('code.txt').read().strip()
stdout = open('stdout.txt').read().splitlines()
stderr = open('stderr.txt').read().splitlines()
if code != '0':
score = 0
feedback = (
'Cannot check the submission.\n\nPerhaps your program '
'has fallen into an infinite loop or created too many objects in memory. '
'If you are sure that this is not the case, please send the report to [email protected]\n'
'stdout:\n{stdout}\n\nstderr:\n{stderr}'
.format(stdout='\n'.join(stdout), stderr='\n'.join(stderr))
)

elif any(line.startswith(FAILED_TEST_BEGIN) for line in stdout):
score = 0
output = []
output_started = False

for line in stdout:
if output_started and line.startswith(FAILED_TEST_CONTINUE):
output.append(line[len(FAILED_TEST_CONTINUE):])

if not output_started and line.startswith(FAILED_TEST_BEGIN):
output_started = True
output.append(line[len(FAILED_TEST_BEGIN):])

feedback = '\n'.join(output).strip()

result = {
'score': score,
'feedback': feedback,
}
print(json.dumps(result))

0 comments on commit 7c4bc4d

Please sign in to comment.