-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram_checker.sh
executable file
·41 lines (35 loc) · 1.19 KB
/
program_checker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env bash
#Title : program_checker.sh
#Usage : bash program_checker.sh program.c path_to_test.in
#Author : pmorvalho
#Date : July 20, 2022
#Description : Checks if a program is consistent with a set of IO tests for a given lab and exercise
#Notes : Outputs WRONG\n (resp. CORRECT\n) dependeing on failing (resp. passing) the input test
# (C) Copyright 2022 Pedro Orvalho.
#==============================================================================
initial_dir=$(pwd)
prog_2_check=$1
test_name=$2
dataset=$initial_dir"/C-Pack-IPAs"
prog_name=$(echo $prog_2_check | rev | cut -d '/' -f 1 | rev)
wdir="wdir_"$prog_name
if [[ ! -d $wdir ]]; then
mkdir -p $wdir
fi
cp $prog_2_check $wdir/$prog_name
cp prints.* $wdir/.
cd $wdir
#gcc -O3 -ansi -Wall $prog_name -lm -o prog_2_check.out 2> war.txt
gcc $prog_name prints.c -o prog_2_check.out 2> war.txt
t=$(echo $test_name | sed -e "s/\.in//" | sed -e "s/\.out//")
t_id=$(echo $t | rev | cut -d '/' -f 1 | rev)
timeout 10s ./prog_2_check.out < $initial_dir/$t".in" > "p-"$t_id".out"
d=$(diff -w -B "p-"$t_id".out" $initial_dir/$t".out")
if [[ $d == "" ]];
then
echo "CORRECT"
else
echo "WRONG"
fi
cd $initial_dir
rm -rf $wdir