-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-test
executable file
·68 lines (51 loc) · 1.67 KB
/
run-test
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /bin/bash
if [ -z $1 ] || [ -z $2 ]; then
echo 'run-test [SUITE] [TEST_NAME]'
exit 1;
fi
if [ ! -z $3 ] && [ $3 == "DEBUG" ]; then
echo "Debug output enabled";
DEBUG=true;
fi
if [ -z $EXTRACTED_JAVA_RT_PATH ]; then
echo 'You must export a path to a directory containing all the Java RT classes as [EXTRACTED_JAVA_RT_PATH]'
exit 1;
fi
BASE_TEST_PATH=test-resources/test-cases;
VM_OUT=vm.out;
PRINTLN_OUT=println.out;
JAVA_FILE_PATH=$BASE_TEST_PATH/$1/$2.java;
EXPECTED_FILE=$JAVA_FILE_PATH.expected;
BUNDLE_DIR=$JAVA_FILE_PATH.bundle;
CLASS_NAME=`basename -s .java $JAVA_FILE_PATH`;
CLASS_FILE_NAME=$CLASS_NAME.class;
if [ ! -f $JAVA_FILE_PATH ]; then
echo "No file at <$JAVA_FILE_PATH>";
exit 1;
fi
TMP_DIR=`mktemp -d` || (echo 'Unable to create temporary directory'; exit 1);
if [ -d $BUNDLE_DIR ]; then
echo "Using bundle"
javac -d $TMP_DIR $JAVA_FILE_PATH $(ls $BUNDLE_DIR/*.java) || (echo 'Unable to compile bundled classes'; exit 1);
else
javac -d $TMP_DIR $JAVA_FILE_PATH || (echo 'Unable to compile class'; exit 1);
fi
echo "Running test [$CLASS_NAME]"
cargo run -q $EXTRACTED_JAVA_RT_PATH $(ls $TMP_DIR/*.class) $CLASS_NAME > $TMP_DIR/$VM_OUT;
cat $TMP_DIR/$VM_OUT | grep "OUT: " > $TMP_DIR/$PRINTLN_OUT;
diff -q $TMP_DIR/$PRINTLN_OUT $EXPECTED_FILE > /dev/null;
if [[ $? -eq 0 ]]; then
echo -e '\033[32mPASSED\033[0m';
if [ ! -z $DEBUG ]; then
cat $TMP_DIR/$VM_OUT;
fi
else
echo -e '\033[31mFAILED\033[0m';
echo "--VM Output--";
cat $TMP_DIR/$VM_OUT;
echo "Classfile: $TMP_DIR/$CLASS_FILE_NAME"
echo '--Expected--';
cat $EXPECTED_FILE;
echo '--Actual--';
cat $TMP_DIR/$PRINTLN_OUT;
fi