KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_job_sch_erc.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 2
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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
21#include <jobs/job_sch_erc.h>
22#include <nlohmann/json.hpp>
23
24
25BOOST_AUTO_TEST_SUITE( JobSchErc )
26
27
28// Regression test for https://gitlab.com/kicad/code/kicad/-/issues/23967
29// A transient working output path (applied when the configured filename is empty)
30// must not be serialized back into the jobset file.
31BOOST_AUTO_TEST_CASE( WorkingOutputPathNotPersisted )
32{
33 JOB_SCH_ERC job;
34
35 BOOST_REQUIRE( job.GetConfiguredOutputPath().IsEmpty() );
36
37 job.SetWorkingOutputPath( wxS( "my-project-erc.rpt" ) );
38
39 nlohmann::json j;
40 job.ToJson( j );
41
42 BOOST_CHECK( j.contains( "output_filename" ) );
43 BOOST_CHECK_EQUAL( j.value( "output_filename", "non-empty" ), "" );
44 BOOST_CHECK( job.GetConfiguredOutputPath().IsEmpty() );
45}
46
47
48// A configured (user-supplied) output path must round-trip through JSON.
49BOOST_AUTO_TEST_CASE( ConfiguredOutputPathPersisted )
50{
51 JOB_SCH_ERC job;
52 job.SetConfiguredOutputPath( wxS( "custom-erc.rpt" ) );
53
54 nlohmann::json j;
55 job.ToJson( j );
56
57 BOOST_CHECK_EQUAL( j.value( "output_filename", "" ), "custom-erc.rpt" );
58}
59
60
61// Setting a configured path after a transient working path was seeded (from a prior run with an
62// empty filename) must let the new configured path win. Otherwise a user who runs the job once
63// with an empty filename and then edits the config to supply a real filename will still hit the
64// stale generated fallback on the next run.
65BOOST_AUTO_TEST_CASE( ConfiguredOutputPathOverridesWorkingPath )
66{
67 JOB_SCH_ERC job;
68
69 job.SetWorkingOutputPath( wxS( "generated-erc.rpt" ) );
70 job.SetConfiguredOutputPath( wxS( "custom-erc.rpt" ) );
71
72 BOOST_CHECK( job.GetWorkingOutputPath().IsEmpty() );
73 BOOST_CHECK( job.GetFullOutputPath( nullptr ) == wxS( "custom-erc.rpt" ) );
74}
75
76
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
Definition job.cpp:163
wxString GetFullOutputPath(PROJECT *aProject) const
Returns the full output path for the job, taking into account the configured output path,...
Definition job.cpp:156
wxString GetWorkingOutputPath() const
Returns the working output path for the job, if one has been set.
Definition job.h:246
wxString GetConfiguredOutputPath() const
Returns the configured output path for the job.
Definition job.h:235
virtual void ToJson(nlohmann::json &j) const
Definition job.cpp:67
void SetWorkingOutputPath(const wxString &aPath)
Sets a transient output path for the job, it takes priority over the configured output path when GetF...
Definition job.h:241
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(WorkingOutputPathNotPersisted)
BOOST_CHECK_EQUAL(result, "25.4")