piston/packages/test.sh

22 lines
746 B
Bash
Raw Normal View History

2021-04-24 09:35:14 +02:00
#!/usr/bin/env bash
AUTH_HEADER="Authorization: $API_KEY"
for test_file in */*/test.*
do
IFS='/' read -ra test_parts <<< "$test_file"
2021-04-25 03:10:18 +02:00
IFS='.' read -ra file_parts <<< "$(basename $test_file)"
language=${file_parts[1]}
2021-04-24 09:35:14 +02:00
lang_ver=${test_parts[1]}
test_src=$(python3 -c "import json; print(json.dumps(open('$test_file').read()))")
json='{"language":"'$language'","version":"'$lang_ver'","files":[{"content":'$test_src'}]}'
result=$(curl -s -XPOST -H "Content-Type: application/json" -d "$json" https://emkc.org/api/v2/piston/execute -H $AUTH_HEADER)
echo "==$test_file: $language-$lang_ver=="
#jq '.' <<<"$result"
2021-04-25 07:17:19 +02:00
jq -r 'if (.run.stdout | contains("OK") ) then (.run.stdout) else (.compile.output + .run.output) end' <<<$result
2021-04-24 09:35:14 +02:00
done