From 517856ad667e9724a2ad8b822f761eed961ad5a7 Mon Sep 17 00:00:00 2001 From: Eric Paniagua Date: Sun, 6 Sep 2020 10:23:55 -0700 Subject: [PATCH] Factor out common test headers into setup-googltest.h. Signed-off-by: Eric Paniagua --- testing/Makefile | 6 +-- testing/common/fix-macros.h | 14 ++----- testing/common/setup-googletest.h | 40 ++++++++++++++++++++ testing/issue_840/test/simulator_test.cpp | 13 +------ testing/kaleidoscope/test/simulator_test.cpp | 13 +------ 5 files changed, 48 insertions(+), 38 deletions(-) create mode 100644 testing/common/setup-googletest.h diff --git a/testing/Makefile b/testing/Makefile index fffb10d9..f7719680 100644 --- a/testing/Makefile +++ b/testing/Makefile @@ -1,4 +1,4 @@ -COMMON_LIB_DIR?=${PWD}/lib +LIB_DIR?=${PWD}/lib TEST_DIRS=$(shell dirname $(wildcard */Makefile)) DIRS=googletest hello-simulator kaleidoscope common issue_840 @@ -7,7 +7,7 @@ CLEANDIRS = $(DIRS:%=clean-%) .PHONY: subdirs $(CLEANDIRS) clean: googletest/Makefile $(CLEANDIRS) - rm -rf "$(COMMON_LIB_DIR)" + rm -rf "$(LIB_DIR)" $(CLEANDIRS): cd $(@:clean-%=%) && $(MAKE) clean @@ -22,7 +22,7 @@ googletest/Makefile: cd googletest && cmake . common: - cd common && COMMON_LIB_DIR="${COMMON_LIB_DIR}" $(MAKE) + cd common && LIB_DIR="${LIB_DIR}" $(MAKE) hello-simulator: @: diff --git a/testing/common/fix-macros.h b/testing/common/fix-macros.h index 4ca9bd22..0ba58308 100644 --- a/testing/common/fix-macros.h +++ b/testing/common/fix-macros.h @@ -14,21 +14,13 @@ * this program. If not, see . */ -#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 max #undef T #undef U #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(); \ - } diff --git a/testing/common/setup-googletest.h b/testing/common/setup-googletest.h new file mode 100644 index 00000000..753cc863 --- /dev/null +++ b/testing/common/setup-googletest.h @@ -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 . + */ + +// 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(); \ + } diff --git a/testing/issue_840/test/simulator_test.cpp b/testing/issue_840/test/simulator_test.cpp index 321c1cc1..a4dd8c31 100644 --- a/testing/issue_840/test/simulator_test.cpp +++ b/testing/issue_840/test/simulator_test.cpp @@ -14,18 +14,7 @@ * this program. If not, see . */ -#include "kaleidoscope/key_defs_keyboard.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 - -#include "testing/common/matchers.h" -#include "testing/common/VirtualDeviceTest.h" +#include "testing/common/setup-googletest.h" SETUP_GOOGLETEST(); diff --git a/testing/kaleidoscope/test/simulator_test.cpp b/testing/kaleidoscope/test/simulator_test.cpp index 95e8774a..ebef4c07 100644 --- a/testing/kaleidoscope/test/simulator_test.cpp +++ b/testing/kaleidoscope/test/simulator_test.cpp @@ -14,18 +14,7 @@ * this program. If not, see . */ -#include "kaleidoscope/key_defs_keyboard.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 - -#include "testing/common/matchers.h" -#include "testing/common/VirtualDeviceTest.h" +#include "testing/common/setup-googletest.h" SETUP_GOOGLETEST();