Skip to content

Commit

Permalink
Migrate build to CMake and standard github workflows
Browse files Browse the repository at this point in the history
Replace makefiles with CMakeLists.txt. This will allow for IDE and
platform agnostic builds of FFF.

Update the CI for FFF to use github workflows which don't depend on MS VC.
The workflow added will verify the pull requests sent to master buy
running 'buildandtest' which mirrors the developer workflow.

Signed-off-by: Yuval Peress <peress@google.com>
  • Loading branch information
yperess committed Aug 5, 2022
1 parent ff70585 commit 2eb067e
Show file tree
Hide file tree
Showing 71 changed files with 303 additions and 1,586 deletions.
13 changes: 0 additions & 13 deletions .appveyor.yml

This file was deleted.

39 changes: 0 additions & 39 deletions .github/workflows/msbuild.yml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/verify_pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Check PR

on:
pull_request:
branches:
- master

jobs:
check-pr:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v3
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build
- name: Build
run: cmake --build ${{github.workspace}}/build
- name: Test
run: ctest --test-dir ${{github.workspace}} --output-on-failure
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ bld/
# Visual Studio 2015/2017 cache/options directory
.vs/

# IntelliJ IDE project directory
.idea/

# Visual C++ cache files
ipch/
*.aps
Expand Down
34 changes: 34 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2022 Google LLC
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
project(fff)

set(CMAKE_CXX_STANDARD 11)

# Add the gtest library which will be used below
add_subdirectory(gtest)

# Enable ctest
enable_testing()

# Generate fff.h if fakegen.rb changed
add_custom_command(
OUTPUT
${CMAKE_CURRENT_LIST_DIR}/fff.h
COMMAND
ruby ${CMAKE_CURRENT_LIST_DIR}/fakegen.rb >> ${CMAKE_CURRENT_LIST_DIR}/fff.h
DEPENDS
${CMAKE_CURRENT_LIST_DIR}/fakegen.rb
${CMAKE_CURRENT_LIST_DIR}/LICENSE
)
add_custom_target(fff_h DEPENDS ${CMAKE_CURRENT_LIST_DIR}/fff.h)

# Add an interface library for fff.h
add_library(fff INTERFACE)
add_dependencies(fff fff_h)
target_include_directories(fff INTERFACE ${CMAKE_CURRENT_LIST_DIR})

# Add tests and samples
add_subdirectory(test)
add_subdirectory(examples)
10 changes: 0 additions & 10 deletions Makefile

This file was deleted.

12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
fff is a micro-framework for creating fake C functions for tests. Because life
is too short to spend time hand-writing fake functions for testing.

## Running all tests

### Linux / MacOS
To run all the tests and sample apps, simply call `$ buildandtest`. This script
will call down into CMake with the following:

```shell
cmake -GNinja -B build
cmake --build build
ctest --test-dir build --output-on-failure
```

## Hello Fake World!

Say you are testing an embedded user interface and you have a function that
Expand Down
27 changes: 11 additions & 16 deletions buildandtest
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
#!/bin/bash
set -e

cat LICENSE > fff.h
echo >> fff.h
ruby fakegen.rb >> fff.h
make clean
make all
build/fff_test_c
build/fff_test_cpp --gtest_output=xml:build/test_results.xml
build/ui_test_ansic
build/ui_test_cpp --gtest_output=xml:build/example_results.xml
build/fff_test_glob_c
build/fff_test_glob_cpp --gtest_output=xml:build/test_global_results.xml
build/driver_testing --gtest_output=xml:build/driver_testing.xml
build/driver_testing_fff --gtest_output=xml:build/driver_testing_fff.xml
build/weak_linking/test_display
build/weak_linking/test_sensor
build/weak_linking/test_main
# Clear the environment
rm -fr build fff.h
mkdir build

# Configure the build
cmake -GNinja -B build || exit -1

# Build all targets
cmake --build build || exit -1

# Run all tests
ctest --test-dir build --output-on-failure
6 changes: 6 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright 2022 Google LLC
# SPDX-License-Identifier: Apache-2.0

add_subdirectory(driver_testing)
add_subdirectory(embedded_ui)
add_subdirectory(weak_linking)
9 changes: 0 additions & 9 deletions examples/Makefile

This file was deleted.

31 changes: 31 additions & 0 deletions examples/driver_testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2022 Google LLC
# SPDX-License-Identifier: Apache-2.0

# Create the driver test binary
add_executable(driver_test
src/driver.c
src/driver.test.cpp
)
target_include_directories(driver_test PRIVATE include)
target_link_libraries(driver_test PRIVATE gtest fff)
target_compile_definitions(driver_test PUBLIC TEST_USER_OWN_TR1_TUPLE=1 TESTING)

# Create the driver fff test binary
add_executable(driver_fff_test
src/driver.c
src/driver.test.fff.cpp
)
target_include_directories(driver_fff_test PRIVATE include)
target_link_libraries(driver_fff_test PRIVATE gtest fff)
target_compile_definitions(driver_fff_test PUBLIC TEST_USER_OWN_TR1_TUPLE=1 TESTING)

# Add tests to ctest
add_test(
NAME driver_test
COMMAND $<TARGET_FILE:driver_test>
)

add_test(
NAME driver_fff_test
COMMAND $<TARGET_FILE:driver_fff_test>
)
64 changes: 0 additions & 64 deletions examples/driver_testing/Makefile

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern "C"
#include "driver.h"
#include "registers.h"
}
#include "../../fff.h"
#include "../../../fff.h"
#include <gtest/gtest.h>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern "C"{
#include "registers.h"
#include "hardware_abstraction.h"
}
#include "../../fff.h"
#include "fff.h"
#include <gtest/gtest.h>

DEFINE_FFF_GLOBALS;
Expand Down
23 changes: 23 additions & 0 deletions examples/embedded_ui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2022 Google LLC
# SPDX-License-Identifier: Apache-2.0

# Create the ui_test_ansic test binary
add_executable(ui_test_ansic src/UI_test_ansic.c src/UI.c)
target_include_directories(ui_test_ansic PRIVATE include)
target_link_libraries(ui_test_ansic PRIVATE fff)

# Create the ui_test_cpp test binary
add_executable(ui_test_cpp src/UI_test_cpp.cpp src/UI.c)
target_include_directories(ui_test_cpp PRIVATE include)
target_link_libraries(ui_test_cpp PRIVATE gtest fff)

# Add tests to ctest
add_test(
NAME ui_test_ansic
COMMAND $<TARGET_FILE:ui_test_ansic>
)

add_test(
NAME ui_test_cpp
COMMAND $<TARGET_FILE:ui_test_cpp>
)
Loading

0 comments on commit 2eb067e

Please sign in to comment.