Skip to content

Commit

Permalink
Merge pull request #45 from RobertByrnes/master
Browse files Browse the repository at this point in the history
Use of FakeIt as a dependency with supporting fixes
  • Loading branch information
FabioBatSilva authored Jun 3, 2023
2 parents 45b9cf9 + 93dbb2b commit e8f5f2f
Show file tree
Hide file tree
Showing 14 changed files with 1,525 additions and 566 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.pioenvs
.piolibdeps
/external/unity/*-repo/
/external/fakeit/*-repo/
/build/
/.cproject
/.project
Expand All @@ -11,4 +12,7 @@
!/Makefile
/Testing/*
.pio/*
.vscode/*
.vscode/*
/test/test_main.cpp
output.txt
error.txt
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
cmake_minimum_required(VERSION 3.2.2)
project(ArduinoFake VERSION 0.1)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)

# Include external libs
add_subdirectory(external)
add_subdirectory(external/fakeit)
add_subdirectory(external/unity)

# Targets that we develop here
enable_testing()
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
default_target: all

.PHONY: all
all: clean build test clean
all: clean build deploy test clean

.PHONY: cmake
cmake:
Expand All @@ -27,3 +27,8 @@ clean:
@rm -rf $(CURDIR)/build/*
@rm -rf $(CURDIR)/.pioenvs/*
@rm -rf $(CURDIR)/.pio/*

.PHONY: deploy
deploy:
cp $(CURDIR)/external/fakeit/fakeit-repo/single_header/standalone/* $(CURDIR)/src

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

`ArduinoFake` is a simple mocking framework for Arduino.
`ArduinoFake` is based on [FakeIt](https://github.com/eranpeer/FakeIt) and can be used for testing your arduino project natively. No arduino required !

#

## Quickstart

Expand Down
1 change: 1 addition & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Include external libs
add_subdirectory(unity)
add_subdirectory(fakeit)
18 changes: 18 additions & 0 deletions external/fakeit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.2.2)
project(fakeit VERSION 2.4.0 LANGUAGES CXX)

include(git-download)

set(REPO_DIR ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}-repo)

download_repo(
URL "https://github.com/eranpeer/FakeIt.git"
TAG ${PROJECT_VERSION}
CLONE_DIR ${REPO_DIR}
)

add_library(${PROJECT_NAME} INTERFACE)

target_include_directories(${PROJECT_NAME} INTERFACE
${REPO_DIR}/single_header/standalone/
)
14 changes: 12 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:native]
platform = native
build_flags = -std=gnu++11
test_build_src = yes
build_flags = -std=gnu++17
test_build_src = yes
6 changes: 3 additions & 3 deletions src/ArduinoFake.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#define USBCON
#endif

#include <map>
#include <unordered_map>
#include <cstring>
#include <cstdint>
#include <stdexcept>
#include "fakeit/fakeit.hpp"
#include "fakeit.hpp"

#include "arduino/Arduino.h"

Expand Down Expand Up @@ -96,7 +96,7 @@ class ArduinoFakeContext
public:
ArduinoFakeInstances* Instances = new ArduinoFakeInstances();
ArduinoFakeMocks* Mocks = new ArduinoFakeMocks();
std::map<void*, void*> Mapping;
std::unordered_map<void*, void*> Mapping;

_ArduinoFakeInstanceGetter1(Print)
_ArduinoFakeInstanceGetter1(Stream)
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ aux_source_directory(./fakeit SRC_LIST)
aux_source_directory(./arduino SRC_LIST)

add_library(${PROJECT_NAME} SHARED ${SRC_LIST})

target_link_libraries(${PROJECT_NAME} fakeit)
2 changes: 1 addition & 1 deletion src/FunctionFake.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "fakeit/fakeit.hpp"
#include "fakeit.hpp"

struct FunctionFake
{
Expand Down
Loading

0 comments on commit e8f5f2f

Please sign in to comment.