cse15l-lab-reports

Lab Report 5

Optimizing Week 7 Lab and Lab Report 4

To clearly show when the JUnit tests fail and when they succeed after fixing the bug, I will be creating 2 bash scripts instead of just one. But you can also combine them by following the alternative instructions labeled “Step 4 (modified)” at the end of the document.

Step 1: Fork the repo

If you already have a copy of lab7 in your github, you will need to delete it.
Go to lab7 settings
Screen Shot 2023-03-12 at 6 05 20 PM
Then scroll down to the very bottom of general
Screen Shot 2023-03-12 at 6 06 41 PM
Click on “Delete this repository” and follow the instructions
Screen Shot 2023-03-12 at 6 07 31 PM
Now, you can go back to the repo of lab7 that you were given to clone, here is the link if you need it
Press “fork” and then press “create fork” when prompted

Screen Shot 2023-03-12 at 6 12 48 PM

Step 3: Remote Log In (XYZ to be replaced by whatever 3-letter combination is in your log in)

Open your terminal and type the following command:

ssh cs15lwi23XYZ@ieng6.ucsd.edu <enter>

Screen Shot 2023-03-12 at 4 20 13 PM

Step 4: Creating the first Bash Script

For this bash script, our goal is to make sure that there are no pre-existing copies of lab 7 already downloaded, clone lab7 onto the remote machine, and run the JUnit tests from ListExamplesTests.java

Run the following command:
touch step1.sh <enter> Touch searches for the file and if it’s not found, it creates the file.
Run the following command:
nano step1.sh <enter> Nano opens the file so it can be edited.

Type out the following code snippets in step1.sh:

Line 1 removes any pre-existing copies of lab7:

rm -rf ~/lab7 <enter>


Line 2 clones the repo onto the local machine (the link should be replaced by the link you copied earlier):

git clone git@github.com:Hall003/lab7.git <enter>


Line 3 changes the working directory to lab7:

cd lab7 <enter>


Line 4 compiles lab7’s java files:

javac -cp .:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar *.java <enter>


Line 5 runs JUnit tests on ListExamplesTests:

java -cp .:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar org.junit.runner.JUnitCore ListExamplesTests <enter>
Press Ctrl+O to save and press Enter to confirm changes
Your file should look like this: Screen Shot 2023-03-12 at 4 33 10 PM
Then, to exit, press Ctrl+X

Step 5: Creating the second Bash Script

For this bash script we want to edit the ListExamples.java files, re-run the JUnit tests, and commit then push the updated file to our forked repo

Run the following command:
touch step2.sh <enter> Touch searches for the file and if it’s not found, it creates the file.
Run the following command:
nano step2.sh <enter> Nano opens the file so it can be edited.

Type out the following code snippets in step2.sh:

Line 1 changes the working directory to lab7

cd lab7 <enter>


Line 2 uses the sed command to edit ListExamples.java to fix the error

sed -i '43s/index1 += 1;/index2 += 1;/' ListExamples.java <enter>


Line 3 compiles the java files in lab7

javac -cp .:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar *.java <enter>


Line 4 runs JUnit tests on ListExamplesTests

java -cp .:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar org.junit.runner.JUnitCore ListExamplesTests <enter>


Line 5 adds ListExamples.java to the staging area

git add ListExamples.java <enter>


Line 6 commits the file from the staging area and sets the commit message

git commit -m "Updated" <enter>


Line 7 pushes the committed file to the main branch

git push origin main <enter>
Press Ctrl+O to save and press Enter to confirm changes
Your file should look like this now: Screen Shot 2023-03-12 at 4 46 56 PM
Then, to exit, press Ctrl+X

Step 6: Testing out the scripts

To test step1.sh, type the following command:

bash step1.sh <enter>


Screen Shot 2023-03-12 at 5 34 47 PM

Here, we can see that lab7 was cloned from the repo and one JUnit test failed.


To run step2.sh, type the following command:


bash step2.sh <enter>


Screen Shot 2023-03-12 at 5 37 01 PM

Here, we can see that all JUnit tests pass and that the fixed file was pushed to main.


If you followed the modified version of Step 4, your results will look a bit different, but the overall results are the same

Screen Shot 2023-03-12 at 6 39 39 PM


In either case, if we check our repo we can see that the ListExamples.java file has been updated:


Screen Shot 2023-03-12 at 5 47 17 PM

Step 7: Logging out

Now that we’re done with our task, we can log out of ieng6. To do so, run the following command:

exit <enter>

Screen Shot 2023-03-12 at 5 49 26 PM

Step 4(modified):

For this bash script, our goal is to make sure that there are no pre-existing copies of lab 7 already downloaded, clone lab7 onto the remote machine, and run the JUnit tests from ListExamplesTests.java. Then to fix the bug that caused the failed JUnit test, re-run the JUnit test, and commit and push the modified file to main.

Run the following command:
touch script.sh <enter> Touch searches for the file and if it’s not found, it creates the file.
Run the following command:
nano script.sh <enter> Nano opens the file so it can be edited.

Type out the following code snippets in step1.sh:

Line 1 removes any pre-existing copies of lab7:

rm -rf ~/lab7 <enter>


Line 2 clones the repo onto the local machine (the link should be replaced by the link you copied earlier):

git clone git@github.com:Hall003/lab7.git <enter>


Line 3 changes the working directory to lab7:

cd lab7 <enter>


Line 4 compiles lab7’s java files:

javac -cp .:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar *.java <enter>


Line 5 runs JUnit tests on ListExamplesTests:

java -cp .:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar org.junit.runner.JUnitCore ListExamplesTests <enter>


Line 6 uses the sed command to edit ListExamples.java to fix the error

sed -i '43s/index1 += 1;/index2 += 1;/' ListExamples.java <enter>


Line 7 compiles the java files in lab7

javac -cp .:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar *.java <enter>


Line 8 runs JUnit tests on ListExamplesTests

java -cp .:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar org.junit.runner.JUnitCore ListExamplesTests <enter>


Line 9 adds ListExamples.java to the staging area

git add ListExamples.java <enter>


Line 10 commits the file from the staging area and sets the commit message

git commit -m "Updated" <enter>


Line 11 pushes the committed file to the main branch

git push origin main <enter>
Press Ctrl+O to save and press Enter to confirm changes
Your file should look like this now:

Screen Shot 2023-03-12 at 6 37 29 PM


Then, to exit, press Ctrl+X