Loading ci_cd/.gitlab-ci.yml +3 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ stages: - lab2 - lab3 - lab4 - lab5 - tests include: Loading @@ -14,3 +15,4 @@ include: - local: 'ci_cd/lab2.yml' # Lab 2 - local: 'ci_cd/lab3.yml' # Lab 3 - local: 'ci_cd/lab4.yml' # Lab 4 - local: 'ci_cd/lab5.yml' # Lab 5 No newline at end of file ci_cd/lab5.yml 0 → 100644 +98 −0 Original line number Diff line number Diff line ### Lab 5 prebuild_lab_5: stage: lab5 script: - echo "Changes Detected (if any):"; - git diff --name-only $CI_COMMIT_SHA~ $CI_COMMIT_SHA || echo "No changes found"; - FILES_ADDED=$(git diff --name-only --diff-filter=A HEAD~1 | wc -l) - | # Check if lab5.cpp exists if [ ! -f "lab5.cpp" ]; then echo "lab5.cpp does not exist"; exit 1; fi # Check that only one file was checked in if [ "FILES_ADDED" -ne 1 ]; then echo "Error: Only one file should be committed."; exit 1; fi # Check if lab4.cpp has been merged into master if git ls-tree -r origin/master --name-only | grep -q 'lab4.cpp'; then echo "Lab 4 complete"; else echo "Please have lab 4 merged first"; exit 1; fi - git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_5 artifacts: paths: - base_5 rules: - if: '$CI_COMMIT_REF_NAME == "lab5"' tags: [c++-17] prebuild_lab_5_SKIP: stage: lab5 script: - echo "SKIPPING Lab 5 checks because the branch name is not 'lab5'" rules: - if: '$CI_COMMIT_REF_NAME != "lab5"' tags: [c++-17] compile_lab_5: stage: lab5 script: - echo "Compiling lab5.cpp" - g++ -c lab5.cpp artifacts: paths: - base_5 dependencies: - prebuild_lab_5 rules: - if: '$CI_COMMIT_REF_NAME == "lab5"' tags: [c++-17] lint_lab_5: stage: lab5 script: - echo "Static code check of lab5.cpp" - cppcheck --check-config --enable=all --inconclusive --error-exitcode=1 lab5.cpp tests/LabFive.cpp allow_failure: false artifacts: paths: - base_5 dependencies: - prebuild_lab_5 rules: - if: '$CI_COMMIT_REF_NAME == "lab5"' tags: [cppcheck] test_lab_5: stage: lab5 script: - echo "Testing Lab 5"; - git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_5 - cp lab5.cpp base_5/tests - cd base_5/tests - make lab5 dependencies: - compile_lab_5 rules: - if: '$CI_COMMIT_REF_NAME == "lab5"' tags: [c++-17] # trigger internal tests only upon a merge request into master internal_tests_lab_5: stage: tests script: - git clone https://trachten-gitlab:$INTERNAL_LAB_TESTS@agile.bu.edu/gitlab/ec327/ec327-staff/lab-tests.git - cp -f lab5.cpp lab-tests/internal_tests/ - cd lab-tests/internal_tests - make lab5 rules: - if: '$CI_COMMIT_REF_NAME == "lab5" && $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"' tags: [ c++-17 ] tests/LabFive.cpp 0 → 100644 +84 −0 Original line number Diff line number Diff line #include <iostream> #include <stdexcept> #include <string> #include "lab5.cpp" using namespace std; bool testLogicError(Graph &g, int value) { try { // Call the student's function with input that should trigger the exception. g+=value; } catch (const logic_error& e) { return true; //if it returns logic error } catch (...) { return false; } return false; } bool test_labFive(){ Graph G; if(testLogicError(G, 3)){ cout << "Test 5a failed" << endl; return false; } if(testLogicError(G, 5)){ cout << "Test 5b failed" << endl; return false; } if(!testLogicError(G, 3)){ //should throw a logic error cout << "Test 5c failed" << endl; return false; } if(G.hasEdge(3,5)){ cout << "Test 5d failed" << endl; return false; } G.addEdge(5,3); if(!G.hasEdge(3,5)){ cout << "Test 5e failed" << endl; return false; } if(G[0] != 3){ cout << "Test 5f failed" << endl; return false; } if(G.numVertices() != 2){ cout << "Test 5g failed" << endl; return false; } if(G.numEdges() != 1){ cout << "Test 5h failed" << endl; return false; } // All tests passed return true; } int main(){ bool t0 = test_labFive(); cout << "Lab Five: " << (t0 ? "passed" : "failed") << endl; if (t0) { // all tests passed exit(0); // passed } else { exit(1); // failed } } tests/Makefile +10 −3 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ LAB1_SRCS = LabOne.cpp lab1.cpp $(COMMON_SRCS) LAB2_SRCS = LabTwo.cpp lab2.cpp LAB3_SRCS = LabThree.cpp LAB4_SRCS = LabFour.cpp $(COMMON_SRCS) LAB5_SRCS = LabFive.cpp # Object files COMM_OBJS = Support/Common.o Loading @@ -19,7 +20,8 @@ LAB1_OBJS = LabOne.o lab1.o $(COMM_OBJS) LAB2_OBJS = LabTwo.o lab2.o LAB3_OBJS = LabThree.o LAB4_OBJS = LabFour.o $(COMM_OBJS) OBJS = $(COMM_OBJS) $(LAB0_OBJS) $(LAB1_OBJS) $(LAB2_OBJS) $(LAB3_OBJS) $(LAB4_OBJS) LAB5_OBJS = LabFive.o OBJS = $(COMM_OBJS) $(LAB0_OBJS) $(LAB1_OBJS) $(LAB2_OBJS) $(LAB3_OBJS) $(LAB4_OBJS) $(LAB5_OBJS) # Executable names LAB0_EXEC = lab0 Loading @@ -27,10 +29,11 @@ LAB1_EXEC = lab1 LAB2_EXEC = lab2 LAB3_EXEC = lab3 LAB4_EXEC = lab4 EXEC = $(LAB0_EXEC) $(LAB1_EXEC) $(LAB2_EXEC) $(LAB3_EXEC) $(LAB4_EXEC) LAB5_EXEC = lab5 EXEC = $(LAB0_EXEC) $(LAB1_EXEC) $(LAB2_EXEC) $(LAB3_EXEC) $(LAB4_EXEC) $(LAB5_EXEC) # Default target to build the executable all: $(LAB0_EXEC) $(LAB1_EXEC) $(LAB2_EXEC) $(LAB3_EXEC) $(LAB4_EXEC) all: $(LAB0_EXEC) $(LAB1_EXEC) $(LAB2_EXEC) $(LAB3_EXEC) $(LAB4_EXEC) $(LAB5_EXEC) # Rule to build the executable from object files $(LAB0_EXEC): $(LAB0_OBJS) Makefile Loading @@ -54,6 +57,10 @@ $(LAB4_EXEC): $(LAB4_OBJS) Makefile lab4.cpp $(CXX) $(CXXFLAGS) -o $(LAB4_EXEC) $(LAB4_OBJS) ./$(LAB4_EXEC) $(LAB5_EXEC): $(LAB5_OBJS) Makefile lab5.cpp $(CXX) $(CXXFLAGS) -o $(LAB5_EXEC) $(LAB5_OBJS) ./$(LAB5_EXEC) # Rules to build object files from source files, with dependency on the Common.h header %.o: %.cpp Support/Common.h Makefile $(CXX) $(CXXFLAGS) -c $< -o $@ Loading Loading
ci_cd/.gitlab-ci.yml +3 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ stages: - lab2 - lab3 - lab4 - lab5 - tests include: Loading @@ -14,3 +15,4 @@ include: - local: 'ci_cd/lab2.yml' # Lab 2 - local: 'ci_cd/lab3.yml' # Lab 3 - local: 'ci_cd/lab4.yml' # Lab 4 - local: 'ci_cd/lab5.yml' # Lab 5 No newline at end of file
ci_cd/lab5.yml 0 → 100644 +98 −0 Original line number Diff line number Diff line ### Lab 5 prebuild_lab_5: stage: lab5 script: - echo "Changes Detected (if any):"; - git diff --name-only $CI_COMMIT_SHA~ $CI_COMMIT_SHA || echo "No changes found"; - FILES_ADDED=$(git diff --name-only --diff-filter=A HEAD~1 | wc -l) - | # Check if lab5.cpp exists if [ ! -f "lab5.cpp" ]; then echo "lab5.cpp does not exist"; exit 1; fi # Check that only one file was checked in if [ "FILES_ADDED" -ne 1 ]; then echo "Error: Only one file should be committed."; exit 1; fi # Check if lab4.cpp has been merged into master if git ls-tree -r origin/master --name-only | grep -q 'lab4.cpp'; then echo "Lab 4 complete"; else echo "Please have lab 4 merged first"; exit 1; fi - git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_5 artifacts: paths: - base_5 rules: - if: '$CI_COMMIT_REF_NAME == "lab5"' tags: [c++-17] prebuild_lab_5_SKIP: stage: lab5 script: - echo "SKIPPING Lab 5 checks because the branch name is not 'lab5'" rules: - if: '$CI_COMMIT_REF_NAME != "lab5"' tags: [c++-17] compile_lab_5: stage: lab5 script: - echo "Compiling lab5.cpp" - g++ -c lab5.cpp artifacts: paths: - base_5 dependencies: - prebuild_lab_5 rules: - if: '$CI_COMMIT_REF_NAME == "lab5"' tags: [c++-17] lint_lab_5: stage: lab5 script: - echo "Static code check of lab5.cpp" - cppcheck --check-config --enable=all --inconclusive --error-exitcode=1 lab5.cpp tests/LabFive.cpp allow_failure: false artifacts: paths: - base_5 dependencies: - prebuild_lab_5 rules: - if: '$CI_COMMIT_REF_NAME == "lab5"' tags: [cppcheck] test_lab_5: stage: lab5 script: - echo "Testing Lab 5"; - git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_5 - cp lab5.cpp base_5/tests - cd base_5/tests - make lab5 dependencies: - compile_lab_5 rules: - if: '$CI_COMMIT_REF_NAME == "lab5"' tags: [c++-17] # trigger internal tests only upon a merge request into master internal_tests_lab_5: stage: tests script: - git clone https://trachten-gitlab:$INTERNAL_LAB_TESTS@agile.bu.edu/gitlab/ec327/ec327-staff/lab-tests.git - cp -f lab5.cpp lab-tests/internal_tests/ - cd lab-tests/internal_tests - make lab5 rules: - if: '$CI_COMMIT_REF_NAME == "lab5" && $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"' tags: [ c++-17 ]
tests/LabFive.cpp 0 → 100644 +84 −0 Original line number Diff line number Diff line #include <iostream> #include <stdexcept> #include <string> #include "lab5.cpp" using namespace std; bool testLogicError(Graph &g, int value) { try { // Call the student's function with input that should trigger the exception. g+=value; } catch (const logic_error& e) { return true; //if it returns logic error } catch (...) { return false; } return false; } bool test_labFive(){ Graph G; if(testLogicError(G, 3)){ cout << "Test 5a failed" << endl; return false; } if(testLogicError(G, 5)){ cout << "Test 5b failed" << endl; return false; } if(!testLogicError(G, 3)){ //should throw a logic error cout << "Test 5c failed" << endl; return false; } if(G.hasEdge(3,5)){ cout << "Test 5d failed" << endl; return false; } G.addEdge(5,3); if(!G.hasEdge(3,5)){ cout << "Test 5e failed" << endl; return false; } if(G[0] != 3){ cout << "Test 5f failed" << endl; return false; } if(G.numVertices() != 2){ cout << "Test 5g failed" << endl; return false; } if(G.numEdges() != 1){ cout << "Test 5h failed" << endl; return false; } // All tests passed return true; } int main(){ bool t0 = test_labFive(); cout << "Lab Five: " << (t0 ? "passed" : "failed") << endl; if (t0) { // all tests passed exit(0); // passed } else { exit(1); // failed } }
tests/Makefile +10 −3 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ LAB1_SRCS = LabOne.cpp lab1.cpp $(COMMON_SRCS) LAB2_SRCS = LabTwo.cpp lab2.cpp LAB3_SRCS = LabThree.cpp LAB4_SRCS = LabFour.cpp $(COMMON_SRCS) LAB5_SRCS = LabFive.cpp # Object files COMM_OBJS = Support/Common.o Loading @@ -19,7 +20,8 @@ LAB1_OBJS = LabOne.o lab1.o $(COMM_OBJS) LAB2_OBJS = LabTwo.o lab2.o LAB3_OBJS = LabThree.o LAB4_OBJS = LabFour.o $(COMM_OBJS) OBJS = $(COMM_OBJS) $(LAB0_OBJS) $(LAB1_OBJS) $(LAB2_OBJS) $(LAB3_OBJS) $(LAB4_OBJS) LAB5_OBJS = LabFive.o OBJS = $(COMM_OBJS) $(LAB0_OBJS) $(LAB1_OBJS) $(LAB2_OBJS) $(LAB3_OBJS) $(LAB4_OBJS) $(LAB5_OBJS) # Executable names LAB0_EXEC = lab0 Loading @@ -27,10 +29,11 @@ LAB1_EXEC = lab1 LAB2_EXEC = lab2 LAB3_EXEC = lab3 LAB4_EXEC = lab4 EXEC = $(LAB0_EXEC) $(LAB1_EXEC) $(LAB2_EXEC) $(LAB3_EXEC) $(LAB4_EXEC) LAB5_EXEC = lab5 EXEC = $(LAB0_EXEC) $(LAB1_EXEC) $(LAB2_EXEC) $(LAB3_EXEC) $(LAB4_EXEC) $(LAB5_EXEC) # Default target to build the executable all: $(LAB0_EXEC) $(LAB1_EXEC) $(LAB2_EXEC) $(LAB3_EXEC) $(LAB4_EXEC) all: $(LAB0_EXEC) $(LAB1_EXEC) $(LAB2_EXEC) $(LAB3_EXEC) $(LAB4_EXEC) $(LAB5_EXEC) # Rule to build the executable from object files $(LAB0_EXEC): $(LAB0_OBJS) Makefile Loading @@ -54,6 +57,10 @@ $(LAB4_EXEC): $(LAB4_OBJS) Makefile lab4.cpp $(CXX) $(CXXFLAGS) -o $(LAB4_EXEC) $(LAB4_OBJS) ./$(LAB4_EXEC) $(LAB5_EXEC): $(LAB5_OBJS) Makefile lab5.cpp $(CXX) $(CXXFLAGS) -o $(LAB5_EXEC) $(LAB5_OBJS) ./$(LAB5_EXEC) # Rules to build object files from source files, with dependency on the Common.h header %.o: %.cpp Support/Common.h Makefile $(CXX) $(CXXFLAGS) -c $< -o $@ Loading