1
1
package io .github .utplsql .api ;
2
2
3
+ import io .github .utplsql .api .exception .SomeTestsFailedException ;
3
4
import io .github .utplsql .api .reporter .DocumentationReporter ;
4
5
import io .github .utplsql .api .reporter .Reporter ;
5
6
import oracle .jdbc .OracleConnection ;
@@ -21,6 +22,7 @@ public class TestRunner {
21
22
private List <String > testFiles = new ArrayList <>();
22
23
private List <String > includeObjects = new ArrayList <>();
23
24
private List <String > excludeObjects = new ArrayList <>();
25
+ private boolean failOnErrors = false ;
24
26
25
27
public TestRunner addPath (String path ) {
26
28
this .pathList .add (path );
@@ -72,7 +74,12 @@ public TestRunner excludeObject(String obj) {
72
74
return this ;
73
75
}
74
76
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 {
76
83
for (Reporter r : this .reporterList )
77
84
validateReporter (conn , r );
78
85
@@ -86,16 +93,23 @@ public void run(Connection conn) throws SQLException {
86
93
87
94
// Workaround because Oracle JDBC doesn't support passing boolean to stored procedures.
88
95
String colorConsoleStr = Boolean .toString (this .colorConsole );
96
+ String failOnErrors = Boolean .toString (this .failOnErrors );
89
97
90
98
OracleConnection oraConn = conn .unwrap (OracleConnection .class );
91
99
CallableStatement callableStatement = null ;
92
100
try {
93
101
callableStatement = conn .prepareCall (
94
102
"BEGIN " +
95
103
"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 + "); " +
99
113
"END;" );
100
114
101
115
int paramIdx = 0 ;
@@ -142,6 +156,12 @@ public void run(Connection conn) throws SQLException {
142
156
}
143
157
144
158
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
+ }
145
165
} finally {
146
166
if (callableStatement != null )
147
167
callableStatement .close ();
0 commit comments