From f96458b459e7eb59cc8746fcf1eb0941076f0b45 Mon Sep 17 00:00:00 2001 From: James Knee Date: Mon, 2 Dec 2024 15:51:49 -0500 Subject: [PATCH 1/3] lab5 CI pipeline --- ci_cd/.gitlab-ci.yml | 4 +- ci_cd/lab5.yml | 98 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 ci_cd/lab5.yml diff --git a/ci_cd/.gitlab-ci.yml b/ci_cd/.gitlab-ci.yml index 4d3c2d2..6660c1b 100644 --- a/ci_cd/.gitlab-ci.yml +++ b/ci_cd/.gitlab-ci.yml @@ -5,6 +5,7 @@ stages: - lab2 - lab3 - lab4 + - lab5 - tests include: @@ -13,4 +14,5 @@ include: - local: 'ci_cd/lab1.yml' # Lab 1 - local: 'ci_cd/lab2.yml' # Lab 2 - local: 'ci_cd/lab3.yml' # Lab 3 - - local: 'ci_cd/lab4.yml' # Lab 4 \ No newline at end of file + - local: 'ci_cd/lab4.yml' # Lab 4 + - local: 'ci_cd/lab5.yml' # Lab 5 \ No newline at end of file diff --git a/ci_cd/lab5.yml b/ci_cd/lab5.yml new file mode 100644 index 0000000..0fa1b5a --- /dev/null +++ b/ci_cd/lab5.yml @@ -0,0 +1,98 @@ +### 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 ] -- GitLab From 35c22609b6f478ae2166a5b816178037928334f4 Mon Sep 17 00:00:00 2001 From: James Knee Date: Mon, 2 Dec 2024 15:52:04 -0500 Subject: [PATCH 2/3] lab5 makefile --- tests/Makefile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 4fb9fc9..33ee127 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -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 @@ -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 @@ -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 @@ -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 $@ -- GitLab From 96d6a3d5993228515786263b4d4408ad3115c56a Mon Sep 17 00:00:00 2001 From: James Knee Date: Mon, 2 Dec 2024 15:52:14 -0500 Subject: [PATCH 3/3] lab5 basic tests --- tests/LabFive.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 tests/LabFive.cpp diff --git a/tests/LabFive.cpp b/tests/LabFive.cpp new file mode 100644 index 0000000..1ab0305 --- /dev/null +++ b/tests/LabFive.cpp @@ -0,0 +1,84 @@ +#include +#include +#include + +#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 + } +} + -- GitLab