KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_text_var_issue24442.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one at
18 * http://www.gnu.org/licenses/
19 */
20
23
24#include <schematic.h>
25#include <erc/erc_settings.h>
26#include <erc/erc.h>
28#include <locale_io.h>
29
30
38
39
40// Verifies that ${ERC_ERROR ...} and ${ERC_WARNING ...} tokens trigger an
41// ERC violation regardless of position in the text. Prior to the fix the
42// regex was anchored with `^...$` so only text starting with the token would
43// fire, breaking placeholder patterns like "Fill in: ${ERC_ERROR ...}".
45{
47
48 KI_TEST::LoadSchematic( m_settingsManager, "issue24442", m_schematic );
49
50 ERC_SETTINGS& settings = m_schematic->ErcSettings();
51
52 // Silence noise from other ERC checks; we care only about generic ERC
53 // text-variable violations here.
54 for( int ii = 0; ii < ERCE_LAST; ++ii )
56
60
61 ERC_TESTER tester( m_schematic.get() );
62 tester.TestTextVars( nullptr );
63
64 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
66
67 int genericErrors = 0;
68 int genericWarnings = 0;
69 int unresolvedVars = 0;
70 std::vector<wxString> errorMessages;
71 std::vector<wxString> warningMessages;
72
73 for( int ii = 0; ii < errors.GetCount(); ++ii )
74 {
75 std::shared_ptr<RC_ITEM> rc = errors.GetItem( ii );
76
77 if( rc->GetErrorCode() == ERCE_GENERIC_ERROR )
78 {
79 genericErrors++;
80 errorMessages.push_back( rc->GetErrorMessage( false ) );
81 }
82 else if( rc->GetErrorCode() == ERCE_GENERIC_WARNING )
83 {
84 genericWarnings++;
85 warningMessages.push_back( rc->GetErrorMessage( false ) );
86 }
87 else if( rc->GetErrorCode() == ERCE_UNRESOLVED_VARIABLE )
88 {
89 unresolvedVars++;
90 }
91 }
92
93 // The fixture schematic contains two ${ERC_ERROR ...} texts (one at start,
94 // one mid-string), two ${ERC_WARNING ...} texts (start + middle), and one
95 // escaped \${ERC_ERROR ...} that must NOT count.
96 BOOST_CHECK_EQUAL( genericErrors, 2 );
97 BOOST_CHECK_EQUAL( genericWarnings, 2 );
98
99 // The four matched markers must not double-report as unresolved variables;
100 // only the escaped literal, whose shown text keeps a bare ${...}, remains.
101 BOOST_CHECK_EQUAL( unresolvedVars, 1 );
102
103 auto containsMsg =
104 []( const std::vector<wxString>& aList, const wxString& aNeedle )
105 {
106 for( const wxString& msg : aList )
107 {
108 if( msg.Contains( aNeedle ) )
109 return true;
110 }
111
112 return false;
113 };
114
115 BOOST_CHECK( containsMsg( errorMessages, "start_of_text" ) );
116 BOOST_CHECK( containsMsg( errorMessages, "placeholder_text" ) );
117 BOOST_CHECK( containsMsg( warningMessages, "this_is_warning" ) );
118 BOOST_CHECK( containsMsg( warningMessages, "embedded_warning" ) );
119 BOOST_CHECK( !containsMsg( errorMessages, "not_a_real_error" ) );
120}
Container for ERC settings.
std::map< int, SEVERITY > m_ERCSeverities
void TestTextVars(DS_PROXY_VIEW_ITEM *aDrawingSheet)
Check for any unresolved text variable references.
Definition erc.cpp:389
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
An implementation of the RC_ITEM_LIST interface which uses the global SHEETLIST to fulfill the contra...
int GetCount(int aSeverity=-1) const override
void SetSeverities(int aSeverities) override
std::shared_ptr< RC_ITEM > GetItem(int aIndex) const override
Retrieve a RC_ITEM by index.
@ ERCE_LAST
@ ERCE_UNRESOLVED_VARIABLE
A text variable could not be resolved.
@ ERCE_GENERIC_ERROR
@ ERCE_GENERIC_WARNING
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
std::vector< FAB_LAYER_COLOR > dummy
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_FIXTURE_TEST_CASE(ERCTextVarIssue24442, ERC_TEXT_VAR_FIXTURE)
BOOST_CHECK_EQUAL(result, "25.4")