diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d5f9f88 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,15 @@ +name: Test +on: + push: + branches: [ main ] +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Build container image + run: docker build -t gtest . + - name: Test in container + run: docker run -t gtest \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8b6536c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -os: linux -dist: xenial -language: cpp - -before_install: - - export CURRENT_PROJ_DIR=$(pwd) - - mkdir gtest - - cd gtest - - git clone https://github.com/google/googletest.git - - cd googletest/googletest - - export GTEST_DIR=$(pwd) - - cmake ${GTEST_DIR} - - cd ${CURRENT_PROJ_DIR} - - pip install --user cpp-coveralls - -script: - - make clean - - make - - ./PiezasTest - -after_success: - - coveralls --exclude *Test.cpp --exclude gtest/ --gcov-options '\-lpbc' diff --git a/Dockerfile b/Dockerfile index 7a9a76e..89800f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,33 @@ -FROM ubuntu:xenial -MAINTAINER Kevin Buffardi (kbuffardi@csuchico.edu) -LABEL title="Unit Testing CPP" +FROM ubuntu:latest +LABEL title="CPP Container" LABEL version=0.1 ENV GTEST_REPO=/googletest ENV GTEST_DIR=${GTEST_REPO}/googletest -ENV CXXFLAGS=-std=c++11 ENV WORKDIR=/usr/src WORKDIR /usr/src +# Set Docker arguments +ARG DEBIAN_FRONTEND=noninteractive + # Install dependencies RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive \ apt-get install -y \ build-essential \ g++ \ cmake \ - git-all + git-all \ + dos2unix # Setup GoogleTest -RUN git clone https://github.com/google/googletest ${GTEST_REPO} && \ - mkdir ${GTEST_REPO}/build && \ - cd ${GTEST_REPO}/build && \ - cmake .. -DBUILD_GMOCK=OFF && \ - make && \ - make install && \ - cd ${WORKDIR} +RUN git clone --depth=1 https://github.com/google/googletest ${GTEST_REPO} +RUN mkdir ${GTEST_REPO}/build && cd ${GTEST_REPO}/build \ + && cmake .. -DBUILD_GMOCK=OFF && make && cd ${WORKDIR} + +# Copy repo source into container +COPY . ${WORKDIR} + +# Assure Unix linefeed for all files +RUN find . -type f -print0 | xargs -0 dos2unix -- -# Build and run tests -CMD ["sh","-c","sed -i -e 's/\r$//' test_runner.sh; ${WORKDIR}/test_runner.sh; gcov -rbc *.cpp"] +# Build project +CMD sh -c ${WORKDIR}/test_runner.sh \ No newline at end of file diff --git a/LICENSE b/LICENSE index 66bbf71..0050a8c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 CSU Chico Software Engineering +Copyright (c) 2024 Kevin Buffardi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index 79c3163..cf2f1d0 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,10 @@ # Building GoogleTest and running exercise-gtest unit tests against -# This Makefile is based on the sample Makefile provided in the -# official GoogleTest GitHub Repo v1.7 - -# REMOVED FOR REQUIRED ENV in CI GTEST_DIR = /usr/local/src/googletest/googletest - +# all code in SOURCECODE subdirectory. This Makefile is based on the +# sample Makefile provided in the official GoogleTest GitHub Repo v1.7 # Flags passed to the preprocessor and compiler -CPPFLAGS += --coverage -std=c++11 -isystem $(GTEST_DIR)/include -CXXFLAGS += -g -Wall -Wextra -pthread +CPPFLAGS += --coverage -isystem $(GTEST_DIR)/include -std=c++17 +CXXFLAGS += -g -pthread # All tests produced by this Makefile. TESTS = PiezasTest @@ -21,11 +18,7 @@ GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \ all : $(TESTS) clean : - rm -f $(TESTS) gtest.a gtest_main.a *.o *.gcov *.gcda *.gcno *.gch - -test: - ./PiezasTest - gcov -fbc Piezas.cpp + rm -f $(TESTS) gtest.a gtest_main.a *.o *.gcov *.gcda *.gcno # Builds gtest.a and gtest_main.a. GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS) @@ -44,8 +37,8 @@ gtest.a : gtest-all.o gtest_main.a : gtest-all.o gtest_main.o $(AR) $(ARFLAGS) $@ $^ -# Builds the Piezas class and associated PiezasTest -Piezas.o : Piezas.h $(GTEST_HEADERS) +# Builds the class and associated tests +Piezas.o : Piezas.cpp Piezas.h $(GTEST_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c Piezas.cpp PiezasTest.o : PiezasTest.cpp \ @@ -53,4 +46,4 @@ PiezasTest.o : PiezasTest.cpp \ $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c PiezasTest.cpp PiezasTest : Piezas.o PiezasTest.o gtest_main.a - $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ \ No newline at end of file diff --git a/PiezasTest.cpp b/PiezasTest.cpp index 3157e44..d7388ee 100644 --- a/PiezasTest.cpp +++ b/PiezasTest.cpp @@ -14,7 +14,8 @@ class PiezasTest : public ::testing::Test virtual void TearDown(){} //clean up after each test, (before destructor) }; -TEST(PiezasTest, sanityCheck) +TEST(PiezasTest, smoke_test) { - ASSERT_TRUE(true); -} \ No newline at end of file + Piezas board; + ASSERT_TRUE( true ); +} diff --git a/test_runner.sh b/test_runner.sh index 7fd5d20..fd9cf3d 100755 --- a/test_runner.sh +++ b/test_runner.sh @@ -3,3 +3,4 @@ make clean make ./PiezasTest +gcov -rbc Piezas.cpp \ No newline at end of file