Skip to content

Commit

Permalink
Update for 2024 Actions and Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
kbuffardi committed Dec 2, 2024
1 parent 2f55d6c commit ea7e7d0
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 56 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

33 changes: 18 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
FROM ubuntu:xenial
MAINTAINER Kevin Buffardi ([email protected])
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 8 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -44,13 +37,13 @@ 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 \
Piezas.h $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c PiezasTest.cpp

PiezasTest : Piezas.o PiezasTest.o gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
7 changes: 4 additions & 3 deletions PiezasTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Piezas board;
ASSERT_TRUE( true );
}
1 change: 1 addition & 0 deletions test_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
make clean
make
./PiezasTest
gcov -rbc Piezas.cpp

0 comments on commit ea7e7d0

Please sign in to comment.