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 2 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 "Kaleidoscope.h"
#include "testing/fix-macros.h"
#include <cstring> // for memcpy
#include <vector> // for vector
#include <cstring>
#include "MouseButtons.h"
#include "MouseButtons.h" // for MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_NEXT, MOUSE_PREV, MOUS...
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
namespace kaleidoscope {
namespace testing {

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

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

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

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

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

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

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

@ -16,12 +16,14 @@
#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
namespace kaleidoscope {

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

@ -16,10 +16,11 @@
#include "testing/KeyboardReport.h"
#include "Kaleidoscope.h"
#include "testing/fix-macros.h"
#include <cstring> // for memcpy
#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 testing {

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

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

@ -16,11 +16,11 @@
#pragma once
#include <cstdint>
#include <vector>
#include <cstdint> // for uint8_t, int8_t, uint32_t
#include "HID-Settings.h"
#include "MultiReport/Mouse.h"
#include "HID-Settings.h" // for HID_REPORTID_MOUSE
#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 testing {

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

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

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

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

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

@ -16,10 +16,19 @@
#include "testing/VirtualDeviceTest.h"
#include "HIDReportObserver.h"
#include "testing/HIDState.h"
#include <bitset>
// IWYU pragma: no_include <__algorithm/max.h>
// IWYU pragma: no_include <__tree>
#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 testing {

@ -16,18 +16,24 @@
#pragma once
#include <cstddef>
#include "testing/ExpectedKeyboardReport.h"
#include "testing/ExpectedMouseReport.h"
#include "testing/SimHarness.h"
#include "testing/State.h"
// Out of order due to macro conflicts.
#include "testing/fix-macros.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <memory>
// IWYU pragma: no_include <__memory/unique_ptr.h>
#include <cstddef> // for size_t
#include <cstdint> // for uint32_t, int8_t, uint8_t
#include <initializer_list> // for initializer_list
#include <memory> // IWYU pragma: keep
#include <set> // for set
#include <vector> // for vector
#include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/key_defs.h" // for Key
#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 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++ -*-
* 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
* 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/>.
*/
// No `#pragma once` since these undefs need to have every time a Kaleidoscope/
// Arduino header is included before non-Kaleidoscope/Arduino header. The undefs
// are needed, due to naming conflicts between Arduino and Googletest.
#pragma once
#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 T
#undef U
#undef TEST
#undef min
#include <iostream> // IWYU pragma: export

@ -16,13 +16,12 @@
#pragma once
#include "kaleidoscope/key_defs.h"
#include "testing/SystemControlReport.h"
// For some reason, the `MATCHER_P` macro confuses IWYU into trying to include
// 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
// gtest and gmock.
#include "testing/fix-macros.h"
#include "gmock/gmock.h"
#include "kaleidoscope/key_defs.h" // for Key
#include "testing/gtest.h" // for GMOCK_PP_INTERNAL_FOR_EACH_IMPL_1, GMOCK_PP_INTERNAL_...
namespace kaleidoscope {
namespace testing {

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

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

Loading…
Cancel
Save