Factor out common test headers into setup-googltest.h.

Signed-off-by: Eric Paniagua <epaniagua@google.com>
pull/898/head
Eric Paniagua 4 years ago
parent f2c96e06d1
commit 517856ad66

@ -1,4 +1,4 @@
COMMON_LIB_DIR?=${PWD}/lib LIB_DIR?=${PWD}/lib
TEST_DIRS=$(shell dirname $(wildcard */Makefile)) TEST_DIRS=$(shell dirname $(wildcard */Makefile))
DIRS=googletest hello-simulator kaleidoscope common issue_840 DIRS=googletest hello-simulator kaleidoscope common issue_840
@ -7,7 +7,7 @@ CLEANDIRS = $(DIRS:%=clean-%)
.PHONY: subdirs $(CLEANDIRS) .PHONY: subdirs $(CLEANDIRS)
clean: googletest/Makefile $(CLEANDIRS) clean: googletest/Makefile $(CLEANDIRS)
rm -rf "$(COMMON_LIB_DIR)" rm -rf "$(LIB_DIR)"
$(CLEANDIRS): $(CLEANDIRS):
cd $(@:clean-%=%) && $(MAKE) clean cd $(@:clean-%=%) && $(MAKE) clean
@ -22,7 +22,7 @@ googletest/Makefile:
cd googletest && cmake . cd googletest && cmake .
common: common:
cd common && COMMON_LIB_DIR="${COMMON_LIB_DIR}" $(MAKE) cd common && LIB_DIR="${LIB_DIR}" $(MAKE)
hello-simulator: hello-simulator:
@: @:

@ -14,21 +14,13 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once // No `#pragma once` since these undefs need to have every time a Kaleidoscope/
// Arduino header is included before non-Kaleidoscope/Arduino header.
// #pragma once
#include "Kaleidoscope.h"
#undef min #undef min
#undef max #undef max
#undef T #undef T
#undef U #undef U
#undef TEST #undef TEST
#define SETUP_GOOGLETEST() \
void executeTestFunction() { \
setup(); /* setup Kaleidoscope */ \
/* Turn off virtual_io's input. */ \
Kaleidoscope.device().keyScanner().setEnableReadMatrix(false); \
testing::InitGoogleTest(); \
RUN_ALL_TESTS(); \
}

@ -0,0 +1,40 @@
/* -*- mode: c++ -*-
* Copyright (C) 2020 Eric Paniagua (epaniagua@google.com)
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
// NOTE: This should always be the last header file included in test source files.
#pragma once
#include "kaleidoscope/key_defs_keyboard.h"
#include "Kaleidoscope.h"
// Out of order because `fix-macros.h` clears the preprocessor environment for
// gtest and gmock.
#include "testing/common/fix-macros.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "testing/common/matchers.h"
#include "testing/common/VirtualDeviceTest.h"
#define SETUP_GOOGLETEST() \
void executeTestFunction() { \
setup(); /* setup Kaleidoscope */ \
/* Turn off virtual_io's input. */ \
Kaleidoscope.device().keyScanner().setEnableReadMatrix(false); \
testing::InitGoogleTest(); \
RUN_ALL_TESTS(); \
}

@ -14,18 +14,7 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "kaleidoscope/key_defs_keyboard.h" #include "testing/common/setup-googletest.h"
// Out of order because `fix-macros.h` clears the preprocessor environment for
// gtest and gmock.
#include "testing/common/fix-macros.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <iostream>
#include "testing/common/matchers.h"
#include "testing/common/VirtualDeviceTest.h"
SETUP_GOOGLETEST(); SETUP_GOOGLETEST();

@ -14,18 +14,7 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "kaleidoscope/key_defs_keyboard.h" #include "testing/common/setup-googletest.h"
// Out of order because `fix-macros.h` clears the preprocessor environment for
// gtest and gmock.
#include "testing/common/fix-macros.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <iostream>
#include "testing/common/matchers.h"
#include "testing/common/VirtualDeviceTest.h"
SETUP_GOOGLETEST(); SETUP_GOOGLETEST();

Loading…
Cancel
Save