Run IWYU (with the new tools) on test simulator code

This mixes some manual work (IWYU pragmas, a better solution to the Arduino
preprocessor macros problem) with automated running of the tools.  At this
point, it would be too much work to separate these into distinct commits, and
there isn't that much value to doing so.

There are still some things we could do to make things more robust, as some of
the headers need to be in a certain order, which happens to be in the same sort
order used by IWYU (`testing/*` files need to come after certain headers than
include `Arduino.h`), but it's probably not worth the clutter of adding an `#if
1` just to stop IWYU from re-ordering them.

I tried to get `#pragma push_macro("max")/pop_macro("max")` to work, but ended
up getting completely nonsensical compilation errors, so I gave up on it.

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/1162/head
Michael Richters 3 years ago
parent ee33b228f9
commit 9b04d6663c
No known key found for this signature in database
GPG Key ID: 1288FD13E4EEF0C0

@ -16,12 +16,11 @@
#include "testing/AbsoluteMouseReport.h" #include "testing/AbsoluteMouseReport.h"
#include "Kaleidoscope.h" #include <cstring> // for memcpy
#include "testing/fix-macros.h" #include <vector> // for vector
#include <cstring> #include "MouseButtons.h" // for MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_NEXT, MOUSE_PREV, MOUS...
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "MouseButtons.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,11 +16,11 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint> // for uint16_t, uint32_t, uint8_t, int8_t
#include <vector> #include <vector> // for vector
#include "DeviceAPIs/AbsoluteMouseAPI.h" #include "DeviceAPIs/AbsoluteMouseAPI.h" // for HID_MouseAbsoluteReport_Data_t
#include "HID-Settings.h" #include "HID-Settings.h" // for HID_REPORTID_MOUSE_ABSOLUTE
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,10 +16,10 @@
#include "testing/ConsumerControlReport.h" #include "testing/ConsumerControlReport.h"
#include "Kaleidoscope.h" #include <cstring> // for memcpy
#include "testing/fix-macros.h" #include <vector> // for vector
#include <cstring> #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,11 +16,11 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint> // for uint32_t, uint16_t, uint8_t
#include <vector> #include <vector> // for vector
#include "HID-Settings.h" #include "HID-Settings.h" // for HID_REPORTID_CONSUMERCONTROL
#include "MultiReport/ConsumerControl.h" #include "MultiReport/ConsumerControl.h" // for HID_ConsumerControlReport_Data_t
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,6 +16,9 @@
#include "testing/ExpectedKeyboardReport.h" #include "testing/ExpectedKeyboardReport.h"
#include <cstdint> // for uint8_t, uint32_t
#include <set> // for set
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,10 +16,10 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint> // for uint8_t, uint32_t
#include <vector> #include <set> // for set
#include <set>
#include <string> #include "testing/iostream.h" // for string
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,6 +16,9 @@
#include "testing/ExpectedMouseReport.h" #include "testing/ExpectedMouseReport.h"
#include "MultiReport/Mouse.h" // for (anonymous union)::(anonymous)
#include "testing/MouseReport.h" // for MouseReport::ReportData
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,12 +16,10 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint> // for int8_t, uint32_t, uint8_t
#include <vector>
#include <set>
#include <string>
#include "MouseReport.h" #include "MouseReport.h" // for MouseReport, MouseReport::ReportData
#include "testing/iostream.h" // for string
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,12 +16,14 @@
#include "testing/HIDState.h" #include "testing/HIDState.h"
#include "HID-Settings.h" // IWYU pragma: no_include <__utility/move.h>
#include "testing/fix-macros.h" #include <utility> // IWYU pragma: keep
#include <vector> // for vector
#include "HID-Settings.h" // for HID_REPORTID_CONSUMERCONTROL, HID_REPORTID_GAMEPAD, HID_RE...
#include "testing/iostream.h" // for operator<<, char_traits, cout, ostream, basic_ostream
// TODO(epan): Add proper logging.
#include <iostream>
#define LOG(x) std::cout #define LOG(x) std::cout
namespace kaleidoscope { namespace kaleidoscope {

@ -16,15 +16,18 @@
#pragma once #pragma once
#include "testing/AbsoluteMouseReport.h" // IWYU pragma: no_include <__memory/unique_ptr.h>
#include "testing/ConsumerControlReport.h"
#include "testing/KeyboardReport.h" #include <stddef.h> // for size_t
#include "testing/MouseReport.h" #include <stdint.h> // for uint8_t
#include "testing/SystemControlReport.h" #include <memory> // IWYU pragma: keep
#include <vector> // for vector
// Out of order due to macro conflicts.
#include "testing/fix-macros.h" #include "testing/AbsoluteMouseReport.h" // for AbsoluteMouseReport
#include <memory> #include "testing/ConsumerControlReport.h" // for ConsumerControlReport
#include "testing/KeyboardReport.h" // for KeyboardReport
#include "testing/MouseReport.h" // for MouseReport
#include "testing/SystemControlReport.h" // for SystemControlReport
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,10 +16,11 @@
#include "testing/KeyboardReport.h" #include "testing/KeyboardReport.h"
#include "Kaleidoscope.h" #include <cstring> // for memcpy
#include "testing/fix-macros.h" #include <vector> // for vector<>::iterator, vector
#include <cstring> #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "kaleidoscope/key_defs.h" // for HID_KEYBOARD_FIRST_MODIFIER, HID_LAST_KEY
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,11 +16,11 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint> // for uint8_t, uint32_t
#include <vector> #include <vector> // for vector
#include "HID-Settings.h" #include "HID-Settings.h" // for HID_REPORTID_NKRO_KEYBOARD
#include "MultiReport/Keyboard.h" #include "MultiReport/Keyboard.h" // for HID_KeyboardReport_Data_t
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,12 +16,9 @@
#include "testing/MouseReport.h" #include "testing/MouseReport.h"
#include "Kaleidoscope.h" #include <cstring> // for memcpy
#include "testing/fix-macros.h"
#include <cstring> #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "MouseButtons.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,11 +16,11 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint> // for uint8_t, int8_t, uint32_t
#include <vector>
#include "HID-Settings.h" #include "HID-Settings.h" // for HID_REPORTID_MOUSE
#include "MultiReport/Mouse.h" #include "MouseButtons.h" // for MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_NEXT, MOUSE_PREV, MOUSE_R...
#include "MultiReport/Mouse.h" // for HID_MouseReport_Data_t
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,8 +16,10 @@
#include "testing/SimHarness.h" #include "testing/SimHarness.h"
#include "testing/fix-macros.h" #include <Arduino.h> // for millis
#include <iostream>
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "kaleidoscope/device/device.h" // for Device, VirtualProps::KeyScanner
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,11 +16,11 @@
#pragma once #pragma once
#include <cstddef> #include <cstddef> // for size_t
#include <cstdint> #include <cstdint> // for uint8_t
#include "Kaleidoscope.h" #include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "testing/fix-macros.h" #include "testing/gtest.h" // IWYU pragma: keep
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,15 +16,11 @@
#pragma once #pragma once
#include <cstddef> // IWYU pragma: no_include <__memory/unique_ptr.h>
#include <cstdint>
#include <vector>
#include "testing/HIDState.h" #include <memory> // IWYU pragma: keep
// Out of order due to macro conflicts. #include "testing/HIDState.h" // for HIDState
#include "testing/fix-macros.h"
#include <memory>
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,10 +16,9 @@
#include "testing/SystemControlReport.h" #include "testing/SystemControlReport.h"
#include "Kaleidoscope.h" #include <cstring> // for memcpy
#include "testing/fix-macros.h"
#include <cstring> #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,11 +16,11 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint> // for uint8_t, uint32_t
#include <vector> #include <vector> // for vector
#include "HID-Settings.h" #include "HID-Settings.h" // for HID_REPORTID_SYSTEMCONTROL
#include "MultiReport/SystemControl.h" #include "MultiReport/SystemControl.h" // for HID_SystemControlReport_Data_t
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,10 +16,19 @@
#include "testing/VirtualDeviceTest.h" #include "testing/VirtualDeviceTest.h"
#include "HIDReportObserver.h" // IWYU pragma: no_include <__algorithm/max.h>
#include "testing/HIDState.h" // IWYU pragma: no_include <__tree>
#include <bitset> #include <bitset> // for bitset
#include <vector> // for vector
#include "HIDReportObserver.h" // for HIDReportObserver
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "testing/HIDState.h" // for HIDState, HIDStateBuilder
#include "testing/KeyboardReport.h" // for KeyboardReport
#include "testing/MouseReport.h" // for MouseReport
#include "testing/gtest.h" // for Message, TestPartResult, EXPECT_EQ, ElementsAreArray
#include "testing/iostream.h" // for operator<<, basic_ostream, char_traits, string, cerr
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -16,18 +16,24 @@
#pragma once #pragma once
#include <cstddef> // IWYU pragma: no_include <__memory/unique_ptr.h>
#include "testing/ExpectedKeyboardReport.h" #include <cstddef> // for size_t
#include "testing/ExpectedMouseReport.h" #include <cstdint> // for uint32_t, int8_t, uint8_t
#include "testing/SimHarness.h" #include <initializer_list> // for initializer_list
#include "testing/State.h" #include <memory> // IWYU pragma: keep
#include <set> // for set
// Out of order due to macro conflicts. #include <vector> // for vector
#include "testing/fix-macros.h"
#include "gmock/gmock.h" #include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "gtest/gtest.h" #include "kaleidoscope/key_defs.h" // for Key
#include <memory> #include "testing/ExpectedKeyboardReport.h" // for ExpectedKeyboardReport
#include "testing/ExpectedMouseReport.h" // for ExpectedMouseReport
#include "testing/HIDState.h" // for HIDState
#include "testing/SimHarness.h" // for SimHarness
#include "testing/State.h" // for State
#include "testing/gtest.h" // for Test
#include "testing/iostream.h" // for string
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -0,0 +1,36 @@
/* -*- mode: c++ -*-
* Copyright (C) 2022 Keyboardio, Inc.
*
* 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/>.
*/
#pragma once
#undef TEST
// In order to include gtest files, we need to undefine some macros that
// Arduino.h unwisely exports. Rahter than including "gtest/gtest.h" (et al)
// directly, any simulator code should instead include "testing/gtest.h".
#undef min
#undef max
// The headers listed here other than "gtest/gtest.h" and "gmock/gmock.h" are
// only included to prevent IWYU from inserting them directly into simulator
// source files. This seems mildly preferable to modifying the gtest files
// themselves.
#include "gmock/gmock-matchers.h" // IWYU pragma: export
#include "gmock/gmock.h" // IWYU pragma: export
#include "gtest/gtest-message.h" // IWYU pragma: export
#include "gtest/gtest-test-part.h" // IWYU pragma: export
#include "gtest/gtest.h" // IWYU pragma: export
#include "gtest/gtest_pred_impl.h" // IWYU pragma: export

@ -1,5 +1,5 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Copyright (C) 2020 Eric Paniagua (epaniagua@google.com) * Copyright (C) 2022 Keyboardio, Inc.
* *
* This program is free software: you can redistribute it and/or modify it under * 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 * the terms of the GNU General Public License as published by the Free Software
@ -14,12 +14,12 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// No `#pragma once` since these undefs need to have every time a Kaleidoscope/ #pragma once
// Arduino header is included before non-Kaleidoscope/Arduino header. The undefs
// are needed, due to naming conflicts between Arduino and Googletest.
#undef min // In order to include certain standard library files, we need to undefine some
// macros that Arduino.h unwisely exports. Rahter than including <iostream>
// directly, any simulator code should instead include "testing/iostream.h".
#undef max #undef max
#undef T #undef min
#undef U
#undef TEST #include <iostream> // IWYU pragma: export

@ -16,13 +16,12 @@
#pragma once #pragma once
#include "kaleidoscope/key_defs.h" // For some reason, the `MATCHER_P` macro confuses IWYU into trying to include
#include "testing/SystemControlReport.h" // this file in itself, so we need to block it with the following:
// IWYU pragma: no_include "testing/matchers.h"
// Out of order because `fix-macros.h` clears the preprocessor environment for #include "kaleidoscope/key_defs.h" // for Key
// gtest and gmock. #include "testing/gtest.h" // for GMOCK_PP_INTERNAL_FOR_EACH_IMPL_1, GMOCK_PP_INTERNAL_...
#include "testing/fix-macros.h"
#include "gmock/gmock.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace testing { namespace testing {

@ -18,17 +18,16 @@
#pragma once #pragma once
#include "kaleidoscope/key_defs/keyboard.h" #include <Kaleidoscope.h> // IWYU pragma: keep
#include "Kaleidoscope.h"
// Out of order because `fix-macros.h` clears the preprocessor environment for // Kaleidoscope.h includes Arduino, which unwisely defines `min` and `max` as
// gtest and gmock. // preprocessor macros. We need to undefine these macros before including any
#include "testing/fix-macros.h" // files from the standard library.
#include "gmock/gmock.h" #undef min
#include "gtest/gtest.h" #undef max
#include "testing/matchers.h" #include "testing/VirtualDeviceTest.h" // IWYU pragma: keep
#include "testing/VirtualDeviceTest.h" #include "testing/matchers.h" // IWYU pragma: keep
#define SETUP_GOOGLETEST() \ #define SETUP_GOOGLETEST() \
void executeTestFunction() { \ void executeTestFunction() { \

@ -15,7 +15,6 @@
*/ */
#include "Kaleidoscope.h" #include "Kaleidoscope.h"
#include "testing/fix-macros.h"
#include "testing/setup-googletest.h" #include "testing/setup-googletest.h"

Loading…
Cancel
Save