11package io .github .utplsql .api ;
22
3+ import io .github .utplsql .api .exception .SomeTestsFailedException ;
34import io .github .utplsql .api .reporter .DocumentationReporter ;
45import io .github .utplsql .api .reporter .Reporter ;
56import oracle .jdbc .OracleConnection ;
@@ -21,6 +22,7 @@ public class TestRunner {
2122 private List <String > testFiles = new ArrayList <>();
2223 private List <String > includeObjects = new ArrayList <>();
2324 private List <String > excludeObjects = new ArrayList <>();
25+ private boolean failOnErrors = false ;
2426
2527 public TestRunner addPath (String path ) {
2628 this .pathList .add (path );
@@ -72,7 +74,12 @@ public TestRunner excludeObject(String obj) {
7274 return this ;
7375 }
7476
75- public void run (Connection conn ) throws SQLException {
77+ public TestRunner failOnErrors (boolean failOnErrors ) {
78+ this .failOnErrors = failOnErrors ;
79+ return this ;
80+ }
81+
82+ public void run (Connection conn ) throws SomeTestsFailedException , SQLException {
7683 for (Reporter r : this .reporterList )
7784 validateReporter (conn , r );
7885
@@ -86,16 +93,23 @@ public void run(Connection conn) throws SQLException {
8693
8794 // Workaround because Oracle JDBC doesn't support passing boolean to stored procedures.
8895 String colorConsoleStr = Boolean .toString (this .colorConsole );
96+ String failOnErrors = Boolean .toString (this .failOnErrors );
8997
9098 OracleConnection oraConn = conn .unwrap (OracleConnection .class );
9199 CallableStatement callableStatement = null ;
92100 try {
93101 callableStatement = conn .prepareCall (
94102 "BEGIN " +
95103 "ut_runner.run(" +
96- "a_paths => ?, a_reporters => ?, a_color_console => " + colorConsoleStr + ", " +
97- "a_coverage_schemes => ?, a_source_files => ?, a_test_files => ?, " +
98- "a_include_objects => ?, a_exclude_objects => ?); " +
104+ "a_paths => ?, " +
105+ "a_reporters => ?, " +
106+ "a_color_console => " + colorConsoleStr + ", " +
107+ "a_coverage_schemes => ?, " +
108+ "a_source_files => ?, " +
109+ "a_test_files => ?, " +
110+ "a_include_objects => ?, " +
111+ "a_exclude_objects => ?, " +
112+ "a_fail_on_errors => " + failOnErrors + "); " +
99113 "END;" );
100114
101115 int paramIdx = 0 ;
@@ -142,6 +156,12 @@ public void run(Connection conn) throws SQLException {
142156 }
143157
144158 callableStatement .execute ();
159+ } catch (SQLException e ) {
160+ if (e .getErrorCode () == SomeTestsFailedException .ERROR_CODE ) {
161+ throw new SomeTestsFailedException (e .getMessage (), e );
162+ } else {
163+ throw e ;
164+ }
145165 } finally {
146166 if (callableStatement != null )
147167 callableStatement .close ();
0 commit comments