chore: unify HA manufacturer and add refactor guards
This commit is contained in:
37
test/check_ha_manufacturer.ps1
Normal file
37
test/check_ha_manufacturer.ps1
Normal file
@@ -0,0 +1,37 @@
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).ProviderPath
|
||||
$configPath = (Resolve-Path (Join-Path $repoRoot "include/config.h")).ProviderPath
|
||||
$mqttPath = (Resolve-Path (Join-Path $repoRoot "src/mqtt_client.cpp")).ProviderPath
|
||||
|
||||
$configText = Get-Content -Raw -Path $configPath
|
||||
if ($configText -notmatch 'HA_MANUFACTURER\[\]\s*=\s*"AcidBurns"\s*;') {
|
||||
throw "include/config.h must define HA_MANUFACTURER as exactly ""AcidBurns""."
|
||||
}
|
||||
|
||||
$mqttText = Get-Content -Raw -Path $mqttPath
|
||||
if ($mqttText -notmatch 'device\["manufacturer"\]\s*=\s*HA_MANUFACTURER\s*;') {
|
||||
throw "src/mqtt_client.cpp must assign device[""manufacturer""] from HA_MANUFACTURER."
|
||||
}
|
||||
if ($mqttText -match 'device\["manufacturer"\]\s*=\s*"[^"]+"\s*;') {
|
||||
throw "src/mqtt_client.cpp must not hardcode manufacturer string literals."
|
||||
}
|
||||
|
||||
$roots = @(
|
||||
Join-Path $repoRoot "src"
|
||||
Join-Path $repoRoot "include"
|
||||
)
|
||||
|
||||
$literalHits = Get-ChildItem -Path $roots -Recurse -File -Include *.c,*.cc,*.cpp,*.h,*.hpp |
|
||||
Select-String -Pattern '"AcidBurns"' |
|
||||
Where-Object { (Resolve-Path $_.Path).ProviderPath -ne $configPath }
|
||||
|
||||
if ($literalHits) {
|
||||
$details = $literalHits | ForEach-Object {
|
||||
"$($_.Path):$($_.LineNumber)"
|
||||
}
|
||||
throw "Unexpected hardcoded ""AcidBurns"" literal(s) outside include/config.h:`n$($details -join "`n")"
|
||||
}
|
||||
|
||||
Write-Host "HA manufacturer drift check passed."
|
||||
41
test/test_refactor_smoke/test_refactor_smoke.cpp
Normal file
41
test/test_refactor_smoke/test_refactor_smoke.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <Arduino.h>
|
||||
#include <unity.h>
|
||||
|
||||
#include "../../src/app_context.h"
|
||||
#include "../../src/receiver_pipeline.h"
|
||||
#include "../../src/sender_state_machine.h"
|
||||
#include "config.h"
|
||||
|
||||
static void test_refactor_headers_and_types() {
|
||||
SenderStateMachineConfig sender_cfg = {};
|
||||
sender_cfg.short_id = 0xF19C;
|
||||
sender_cfg.device_id = "dd3-F19C";
|
||||
|
||||
ReceiverSharedState shared = {};
|
||||
ReceiverPipelineConfig receiver_cfg = {};
|
||||
receiver_cfg.short_id = 0xF19C;
|
||||
receiver_cfg.device_id = "dd3-F19C";
|
||||
receiver_cfg.shared = &shared;
|
||||
|
||||
SenderStateMachine sender_sm;
|
||||
ReceiverPipeline receiver_pipe;
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT16(0xF19C, sender_cfg.short_id);
|
||||
TEST_ASSERT_NOT_NULL(receiver_cfg.shared);
|
||||
(void)sender_sm;
|
||||
(void)receiver_pipe;
|
||||
}
|
||||
|
||||
static void test_ha_manufacturer_constant() {
|
||||
TEST_ASSERT_EQUAL_STRING("AcidBurns", HA_MANUFACTURER);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_refactor_headers_and_types);
|
||||
RUN_TEST(test_ha_manufacturer_constant);
|
||||
UNITY_END();
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
|
||||
Reference in New Issue
Block a user