Skip to content

Commit

Permalink
Pass input test name to inwer (#22)
Browse files Browse the repository at this point in the history
* Pass input test's name to inwer

* Fix tests

* Add inwer tests for passing test name as an argument

* Check if 'in_file_name' exists in environ
  • Loading branch information
MasloMaslane authored Nov 17, 2023
1 parent c96579e commit c92733a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sio/executors/inwer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def _run_in_executor(environ, command, executor, **kwargs):

def _run_inwer(environ, use_sandboxes=False):
command = [tempcwd('inwer')]
if 'in_file_name' in environ:
command.append(environ['in_file_name'])
if use_sandboxes:
executor = SupervisedExecutor()
else:
Expand All @@ -49,6 +51,9 @@ def run(environ):
``in_file``: the file redirected to the program's stdin
``in_file_name``: the name of the input file. It's passed to inwer as
the second argument.
``use_sandboxes``: if this key equals ``True``, the program is executed
in the SupervisedExecutor, otherwise the UnsafeExecutor
is used
Expand Down
14 changes: 14 additions & 0 deletions sio/workers/test/sources/inwer_argument.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdio.h>

int main(int argc, char *argv[]) {
if (argc != 2) {
printf("WRONG\nWrong number of arguments");
return 1;
}
if (strcmp(argv[1], "inwer_ok") != 0) {
printf("WRONG\nWrong test name");
return 1;
}
printf("OK\n");
return 0;
}
3 changes: 3 additions & 0 deletions sio/workers/test/test_executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ def inner(env):
yield '/inwer_big_output.c', '/inwer_ok', use_sandboxes, check_inwer_big_output(
use_sandboxes
)
yield '/inwer_argument.c', '/inwer_ok', use_sandboxes, check_inwer_ok
yield '/inwer_argument.c', '/inwer_wrong', use_sandboxes, check_inwer_wrong


@pytest.mark.parametrize(
Expand All @@ -449,6 +451,7 @@ def test_inwer(inwer, in_file, use_sandboxes, callback):
with TemporaryCwd():
env = {
'in_file': in_file,
'in_file_name': os.path.basename(in_file),
'exe_file': inwer_bin,
'use_sandboxes': use_sandboxes,
'inwer_output_limit': SMALL_OUTPUT_LIMIT,
Expand Down

0 comments on commit c92733a

Please sign in to comment.