mirror of
https://github.com/esphome/esphome.git
synced 2026-10-14 10:12:52 +00:00
[tests] Reset shared App state before every host test (#20510)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "esphome/components/logger/logger.h"
|
||||
#include "esphome/core/application.h"
|
||||
|
||||
/*
|
||||
This special main.cpp replaces the default one.
|
||||
@@ -19,6 +20,11 @@ void original_setup() {
|
||||
// =========== AUTO GENERATED CODE END ============
|
||||
}
|
||||
|
||||
// The loop clock and current component one test moves must not leak into the next, like CORE.reset() in Python
|
||||
class ResetAppListener : public ::testing::EmptyTestEventListener {
|
||||
void OnTestStart(const ::testing::TestInfo &) override { esphome::LoopBlockingGuard reset{nullptr, nullptr, 0}; }
|
||||
};
|
||||
|
||||
void setup() {
|
||||
// Log functions call global_logger->log_vprintf_() without a null check,
|
||||
// so we must set up a Logger before any test that triggers logging.
|
||||
@@ -27,6 +33,7 @@ void setup() {
|
||||
test_logger.pre_setup();
|
||||
|
||||
::testing::InitGoogleTest();
|
||||
::testing::UnitTest::GetInstance()->listeners().Append(new ResetAppListener);
|
||||
int exit_code = RUN_ALL_TESTS();
|
||||
// A test folder that never reached the build would otherwise pass as an empty run
|
||||
if (::testing::UnitTest::GetInstance()->total_test_count() == 0) {
|
||||
|
||||
Reference in New Issue
Block a user