Skip to content

Test/macos #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions .github/workflows/debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,47 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
branches: [ master ]

jobs:
build:
build-linux:
runs-on: ubuntu-latest
steps:
- name: Install gtest manually
run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp *.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a
- uses: actions/checkout@v1
- name: configure
run: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Werror" ..
- name: make
run: cd build && make
- name: Run Test
run: /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test
- name: Download, configure and install gtest
run: |
wget https://github.com/google/googletest/archive/release-1.10.0.tar.gz
tar xf release-1.10.0.tar.gz
cd googletest-release-1.10.0
cmake -DBUILD_SHARED_LIBS=OFF .
sudo make install
- name: Checkout the project
uses: actions/checkout@v1
- name: Do some tests
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Werror" ..
make
/home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test

build-macos:
runs-on: macos-latest
steps:
- name: Download, configure and install gtest
run: |
wget https://github.com/google/googletest/archive/release-1.10.0.tar.gz
tar xf release-1.10.0.tar.gz
cd googletest-release-1.10.0
cmake -DBUILD_SHARED_LIBS=OFF .
sudo make install
- name: Checkout the project
uses: actions/checkout@v1
- name: Do some tests
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Werror" ..
VERBOSE=1 make
pwd
/Users/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test
50 changes: 40 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,47 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
branches: [ master ]

jobs:
build:
build-linux:
runs-on: ubuntu-latest
steps:
- name: Install gtest manually
run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp *.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a
- uses: actions/checkout@v1
- name: configure
run: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" ..
- name: make
run: cd build && make
- name: Run Test
run: /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test
- name: Download, configure and install gtest
run: |
wget https://github.com/google/googletest/archive/release-1.11.0.tar.gz
tar xf release-1.11.0.tar.gz
cd googletest-release-1.11.0
cmake -DBUILD_SHARED_LIBS=OFF .
sudo make install
- name: Checkout the project
uses: actions/checkout@v1
- name: Do some tests
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" ..
make
/home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test

build-macos:
runs-on: macos-latest
steps:
- name: Download, configure and install gtest
run: |
wget https://github.com/google/googletest/archive/release-1.11.0.tar.gz
tar xf release-1.11.0.tar.gz
cd googletest-release-1.11.0
cmake -DBUILD_SHARED_LIBS=OFF .
sudo make install
- name: Checkout the project
uses: actions/checkout@v1
- name: Do some tests
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" ..
VERBOSE=1 make
pwd
/Users/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
![github_actions_gtest_example-Release](https://github.com/bastianhjaeger/github_actions_gtest_example/workflows/github_actions_gtest_example-Release/badge.svg?branch=master)
![github_actions_gtest_example-Debug](https://github.com/bastianhjaeger/github_actions_gtest_example/workflows/github_actions_gtest_example-Debug/badge.svg?branch=master)

Example on how to integrate gtest test into [github actions](https://github.com/features/actions).
Example on how to integrate gtest test into [github actions](https://github.com/features/actions).



While there exist other links in the www on how to use it (which did not work for my setup), this repo quickly shows how to add a workflow / action to github that executes your gtest tests and responses with a simple ok / not-ok to highlight on github.

It is plain and simple, but maybe it helps you.
It is plain and simple, but maybe it helps you.

# Setup Actions

Expand All @@ -27,18 +27,25 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Install gtest manually
run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp *.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a
- uses: actions/checkout@v1
- name: configure
run: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" ..
- name: make
run: cd build && make
- name: Run Test
run: /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test
```

The important part is the *"Install gtest manually"* section. This is the plain and simple way to add it.
- name: Download, configure and install gtest
run: |
wget https://github.com/google/googletest/archive/release-1.10.0.tar.gz
tar xf release-1.10.0.tar.gz
cd googletest-release-1.10.0
cmake -DBUILD_SHARED_LIBS=OFF .
sudo make install
- name: Checkout the project
uses: actions/checkout@v1
- name: Do some tests
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" ..
make
/home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test
```

The important part is the *"Download, configure and install gtest"* section. This is the plain and simple way to add it.

# Result

Expand All @@ -59,3 +66,7 @@ mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j8
```

# If you only want to use Makefile

You can `pkg-config --libs gtest gmock` and `pkg-config --cflags gtest gmock`.
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ set(header_path "${${PROJECT_NAME}_SOURCE_DIR}/include/${PROJECT_NAME}")
set(header ${header_path}/${PROJECT_NAME}.h)
set(src ${PROJECT_NAME}.cpp)


add_library(${PROJECT_NAME} SHARED
${header}
${src})
Expand Down
7 changes: 6 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
link_directories("/usr/local/lib")

add_executable(${PROJECT_NAME}.test
AllTests.cpp
${PROJECT_NAME}Test.cpp)
target_link_libraries(${PROJECT_NAME}.test
${PROJECT_NAME} gtest pthread)
target_compile_definitions(${PROJECT_NAME}.test
PRIVATE TEST_DIR="${CMAKE_CURRENT_LIST_DIR}/test")

install(TARGETS ${PROJECT_NAME}.test
DESTINATION "${tool_dest}")

# Mac OS X does not look at these paths
target_include_directories(${PROJECT_NAME}.test PRIVATE "/usr/local/include/")
set(CMAKE_LIBRARY_PATH "/usr/local/lib/")
3 changes: 1 addition & 2 deletions test/github_actions_gtest_exampleTest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <github_actions_gtest_example/github_actions_gtest_example.h>

#include <gtest/gtest.h>

TEST(githubActionsGtestExampleTest, firstTest) {
Expand All @@ -10,6 +9,6 @@ TEST(githubActionsGtestExampleTest, addTest) {
const int a = 1;
const int b = 3;
const int result = githubActionsGtestExample::add(a, b);

EXPECT_EQ( result, a + b );
}