Last active
August 23, 2017 05:22
-
-
Save jeremiah-ang/a80f43fa470fa95e3323521285cb78dd to your computer and use it in GitHub Desktop.
Execute java project with input and output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Set variables | |
PROJECT_NAME=$1 | |
PROJECT_NAME_LOWER=$(echo $PROJECT_NAME | tr '[:upper:]' '[:lower:]') | |
TEST_CASE=$PROJECT_NAME_LOWER$2 | |
PATH_TO_TEST_INPUTS=input | |
PATH_TO_TEST_OUTPUTS=output | |
echo "Project: $PROJECT_NAME" | |
# Compile Java | |
javac $PROJECT_NAME.java | |
if [ $? -ne 0 ] | |
then | |
echo -e ">> " + $1 + ".java didn't compile!" | |
exit 1 | |
fi | |
echo -e ">> Compiled Successfully!"; | |
# Execute Java with input and output into result | |
cp $PATH_TO_TEST_INPUTS/$TEST_CASE.in $TEST_CASE.in.tmp | |
java $PROJECT_NAME < $TEST_CASE.in.tmp > result | |
rm $TEST_CASE.in.tmp | |
# Check for difference | |
DIFF=$(diff $PATH_TO_TEST_OUTPUTS/$TEST_CASE.out result) | |
if [ "$DIFF" != "" ] | |
then | |
echo -e ">> Test Failed!" | |
echo -e $DIFF | |
exit 1 | |
else | |
echo -e ">> Test Success!" | |
fi | |
# Remove other unneccesary files | |
rm result | |
rm *.class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment