Skip to content

Latest commit

 

History

History
143 lines (108 loc) · 5.36 KB

lab-report-6-week-9.md

File metadata and controls

143 lines (108 loc) · 5.36 KB

Week 9 Lab: Grade Server


Grading Script and Output -

grade.sh

1   # remove existing student-submission directory from
2   # previous execution of grade.sh
3   # clone repository into student-submission directory
4   # from first command-line argument
5   rm -rf student-submission
6   git clone $1 student-submission
7
8   # instantiate variables
9   CP=".:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar"
10  ERRORS=0
11  TESTS=0
12  GRADE=0
13
14  # move into student-submission directory
15  cd student-submission
16
17  # check that the appropriate file exists
18  if [ ! -e ListExamples.java ]; then
19      echo $'\n'"ListExamples.java does not exist."$'\n'
20      exit 1
21  fi
22
23  # copy file from student-submisson to working directory
24  # move back to working directory
25  cp ListExamples.java ..
26  cd ..
27
28  # compile all java files and save stderr output to a text file
29  javac -cp $CP *.java 2> compilation.txt
30
31  # check that the compile command produced error output
32  # if so, prints error output and a grade of 0
33  if grep -q error compilation.txt; then
34      echo $'\n'Compilation Error -$'\n\n'"$(head -n -1 compilation.txt)"$'\n\n'Grade: $GRADE
35      exit 1
36  fi
37
38  # run the appropirate test file and save its stdout output to a text file
39  java -cp $CP org.junit.runner.JUnitCore TestListExamples > results.txt
40
41  # print the contents of the test
42  echo $'\n'"$(<results.txt)"
43
44  # calculate the number of errors, tests, and final grade
45  # sed command returns only line 2 from test output
46  ERRORS=$(sed -n 2p results.txt | grep -o 'E' | wc -l)
47  TESTS=$(sed -n 2p results.txt | grep -o '\.' | wc -l)
48  GRADE=$((100 - (100 * ($ERRORS / $TESTS))))
49
50  # calculates the number of passed tests
51  # prints out ratio
52  tests_passed=$(($ERRORS - $TESTS))
53  echo $'\n'${tests_passed#-}"/"$TESTS" tests passed -"
54
55  # prints final grade
56  echo Grade: $GRADE

Output in browser from submission https://github.com/ucsd-cse15l-f22/list-methods-lab3:


Output in browser from submission https://github.com/ucsd-cse15l-f22/list-methods-corrected:


Output in browser from submission https://github.com/ucsd-cse15l-f22/list-methods-compile-error:


Trace of grade.sh with the following submission: https://github.com/ucsd-cse15l-f22/list-methods-compile-error -


Lines 1-4 do not run because they are comments.

Line 5: rm -rf student-submission

  • There is no stdout or stderr and the return code is 0.

Line 6: git clone $1 student-submission

  • Stdout is the following: Cloning into 'student-submission'...
  • There is no stderr and the return code is 0.

Lines 7-8 do not run because they are empty or comments.

Lines 9-12: variable assignment

  • There is no stdout or stderr for these commands and the return code for all these comamnds is 0.

Lines 13-14 do not run because they are empty or comments.

Line 15: cd student-submission

  • There is no stdout or stderr and the return code is 0.

Lines 16-17 do not run because they are empty or comments.

Line 18: if [ ! -e ListExamples.java ]; then

  • This if statement evaluates to false because the file ListExamples.java does exist in the directory student-submission.

Lines 19-21 do not run as a result of the if statement on Line 18 evaluating to false.

Lines 22-24 do not run because they are empty or comments.

Line 25: cp ListExamples.java ..

  • There is no stdout or stderr and the return code is 0.

Line 26: cd ..

  • There is no stdout or stderr and the return code is 0.

Lines 27-28 do not run because they are empty or comments.

Line 29: javac -cp $CP *.java 2> compilation.txt

  • The output for stderr is the following:
    ListExamples.java:15: error: ';' expected
                  result.add(0, s)
                                        ^
    1 error
  • There is no stdout and the return code is 1.

Lines 30-32 do not run because they are empty or comments.

Line 33: if grep -q error compilation.txt; then

  • This if statement evaluates to true because compilation.txt contains stderr output from the command on Line 29, therefore the grep command returns with a code of zero, indicating the compilation has failed.

Line 34: echo $'\n'Compilation Error -$'\n\n'"$(head -n -1 compilation.txt)"$'\n\n'Grade: $GRADE

  • The output for stdout is the following:

    Compilation Error -

    ListExamples.java:15: error: ';' expected
                  result.add(0, s)
                                        ^

    Grade: 0
  • There is no stderr and the return code is 0.

Line 35: exit 1

  • There is no stdout or stderr and the return code is 1, as it exits grade.sh with that return code.

Lines 36-56 do not run because grade.sh terminates and returns an code of 1 on Line 35.