Dump the ERC report as part of the erc failure

This commit is contained in:
Marek Roszko 2024-01-21 16:10:43 -05:00
parent 0147dd8699
commit 1981997ee2
7 changed files with 61 additions and 20 deletions

View File

@ -41,13 +41,8 @@ ERC_REPORT::ERC_REPORT( SCHEMATIC* aSchematic, EDA_UNITS aReportUnits ) :
}
bool ERC_REPORT::WriteTextReport( const wxString& aFullFileName )
wxString ERC_REPORT::GetTextReport()
{
wxFFile file( aFullFileName, wxT( "wt" ) );
if( !file.IsOpened() )
return false;
UNITS_PROVIDER unitsProvider( schIUScale, m_reportUnits );
wxString msg = wxString::Format( _( "ERC report (%s, Encoding UTF8)\n" ),
@ -93,13 +88,20 @@ bool ERC_REPORT::WriteTextReport( const wxString& aFullFileName )
msg << wxString::Format( _( "\n ** ERC messages: %d Errors %d Warnings %d\n" ), total_count,
err_count, warn_count );
// Currently: write report using UTF8 (as usual in Kicad).
// TODO: see if we can use the current encoding page (mainly for Windows users),
// Or other format (HTML?)
file.Write( msg );
return msg;
}
bool ERC_REPORT::WriteTextReport( const wxString& aFullFileName )
{
wxFFile file( aFullFileName, wxT( "wt" ) );
if( !file.IsOpened() )
return false;
file.Write( GetTextReport() );
// wxFFile dtor will close the file.
return true;
}

View File

@ -32,7 +32,25 @@ class ERC_REPORT
public:
ERC_REPORT( SCHEMATIC* aSchematic, EDA_UNITS aReportUnits );
/**
* Returns the ERC report in "text" (human readable) format
*
* @return The complete report
*/
wxString GetTextReport();
/**
* Writes the text report also available via GetTextReport directly to a given file path
*
* @return True if the file write completed successfully, false otherwise
*/
bool WriteTextReport( const wxString& aFullFileName );
/**
* Writes a JSON formatted ERC Report to the given file path
*
* @return True if the file write completed successfully, false otherwise
*/
bool WriteJsonReport( const wxString& aFullFileName );
private:

View File

@ -25,6 +25,7 @@
#include <schematic.h>
#include <erc_settings.h>
#include <erc.h>
#include <erc_report.h>
#include <settings/settings_manager.h>
#include <locale_io.h>
@ -72,8 +73,12 @@ BOOST_FIXTURE_TEST_CASE( ERCGlobalLabels, ERC_REGRESSION_TEST_FIXTURE )
errors.SetSeverities( RPT_SEVERITY_ERROR | RPT_SEVERITY_WARNING );
BOOST_CHECK_MESSAGE( errors.GetCount() == test.second, "Expected " << test.second
<< " errors in " << test.first.ToStdString() << " but got " << errors.GetCount() );
ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MILLIMETRES );
BOOST_CHECK_MESSAGE( errors.GetCount() == test.second,
"Expected " << test.second << " errors in " << test.first.ToStdString()
<< " but got " << errors.GetCount() << "\n"
<< reportWriter.GetTextReport() );
}
}

View File

@ -25,6 +25,7 @@
#include <schematic.h>
#include <erc_settings.h>
#include <erc.h>
#include <erc_report.h>
#include <settings/settings_manager.h>
#include <locale_io.h>
@ -74,8 +75,11 @@ BOOST_FIXTURE_TEST_CASE( ERCHierarchicalSchematics, ERC_REGRESSION_TEST_FIXTURE
errors.SetSeverities( RPT_SEVERITY_ERROR | RPT_SEVERITY_WARNING );
ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MILLIMETRES );
BOOST_CHECK_MESSAGE( errors.GetCount() == test.second,
"Expected " << test.second << " errors in " << test.first.ToStdString()
<< " but got " << errors.GetCount() );
<< " but got " << errors.GetCount() << "\n"
<< reportWriter.GetTextReport() );
}
}

View File

@ -25,6 +25,7 @@
#include <schematic.h>
#include <erc_settings.h>
#include <erc.h>
#include <erc_report.h>
#include <settings/settings_manager.h>
#include <locale_io.h>
@ -77,8 +78,11 @@ BOOST_FIXTURE_TEST_CASE( ERCLabelNotConnected, ERC_REGRESSION_TEST_FIXTURE )
errors.SetSeverities( RPT_SEVERITY_ERROR | RPT_SEVERITY_WARNING );
BOOST_CHECK_MESSAGE( errors.GetCount() == test.second, "Expected " << test.second
<< " errors in " << test.first.ToStdString() << " but got " << errors.GetCount() );
ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MILLIMETRES );
BOOST_CHECK_MESSAGE( errors.GetCount() == test.second, "Expected " << test.second << " errors in " << test.first.ToStdString()
<< " but got " << errors.GetCount() << "\n"
<< reportWriter.GetTextReport() );
}
}

View File

@ -25,6 +25,7 @@
#include <schematic.h>
#include <erc_settings.h>
#include <erc.h>
#include <erc_report.h>
#include <settings/settings_manager.h>
#include <locale_io.h>
@ -79,8 +80,11 @@ BOOST_FIXTURE_TEST_CASE( ERCNoConnect, ERC_REGRESSION_TEST_FIXTURE )
errors.SetSeverities( RPT_SEVERITY_ERROR | RPT_SEVERITY_WARNING );
BOOST_CHECK_MESSAGE( errors.GetCount() == test.second, "Expected " << test.second
<< " errors in " << test.first.ToStdString() << " but got " << errors.GetCount() );
ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MILLIMETRES );
BOOST_CHECK_MESSAGE( errors.GetCount() == test.second, "Expected " << test.second << " errors in " << test.first.ToStdString()
<< " but got " << errors.GetCount() << "\n"
<< reportWriter.GetTextReport() );
}
}

View File

@ -25,6 +25,7 @@
#include <schematic.h>
#include <erc_settings.h>
#include <erc.h>
#include <erc_report.h>
#include <settings/settings_manager.h>
#include <locale_io.h>
@ -73,8 +74,11 @@ BOOST_FIXTURE_TEST_CASE( ERCStackingPins, ERC_REGRESSION_TEST_FIXTURE )
errors.SetSeverities( RPT_SEVERITY_ERROR | RPT_SEVERITY_WARNING );
BOOST_CHECK_MESSAGE( errors.GetCount() == test.second, "Expected " << test.second
<< " errors in " << test.first.ToStdString() << " but got " << errors.GetCount() );
ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MILLIMETRES );
BOOST_CHECK_MESSAGE( errors.GetCount() == test.second, "Expected " << test.second << " errors in " << test.first.ToStdString()
<< " but got " << errors.GetCount() << "\n"
<< reportWriter.GetTextReport() );
}
}