29
29
import org .testng .internal .ClassHelper ;
30
30
import org .testng .internal .Configuration ;
31
31
import org .testng .internal .DynamicGraph ;
32
+ import org .testng .internal .ExitCode ;
32
33
import org .testng .internal .IConfiguration ;
33
34
import org .testng .internal .IResultListener2 ;
34
35
import org .testng .internal .OverrideProcessor ;
@@ -142,16 +143,9 @@ public class TestNG {
142
143
private final Map <Class <? extends IReporter >, IReporter > m_reporters = Maps .newHashMap ();
143
144
private final Map <Class <? extends IDataProviderListener >, IDataProviderListener > m_dataProviderListeners = Maps .newHashMap ();
144
145
145
- protected static final int HAS_FAILURE = 1 ;
146
- protected static final int HAS_SKIPPED = 2 ;
147
- protected static final int HAS_FSP = 4 ;
148
- protected static final int HAS_NO_TEST = 8 ;
149
146
150
147
public static final Integer DEFAULT_VERBOSE = 1 ;
151
148
152
- private int m_status ;
153
- private boolean m_hasTests = false ;
154
-
155
149
// Command line suite parameters
156
150
private int m_threadCount = -1 ;
157
151
private XmlSuite .ParallelMode m_parallelMode = null ;
@@ -185,6 +179,8 @@ public class TestNG {
185
179
private final Map <Class <? extends IAlterSuiteListener >, IAlterSuiteListener > m_alterSuiteListeners = Maps .newHashMap ();
186
180
187
181
private boolean m_isInitialized = false ;
182
+ private org .testng .internal .ExitCodeListener exitCodeListener ;
183
+ private ExitCode exitCode ;
188
184
189
185
/**
190
186
* Default constructor. Setting also usage of default listeners/reporters.
@@ -211,11 +207,10 @@ private void init(boolean useDefaultListeners) {
211
207
}
212
208
213
209
public int getStatus () {
214
- return m_status ;
215
- }
216
-
217
- private void setStatus (int status ) {
218
- m_status |= status ;
210
+ if (!exitCodeListener .hasTests ()) {
211
+ return ExitCode .HAS_NO_TEST ;
212
+ }
213
+ return exitCode .getExitCode ();
219
214
}
220
215
221
216
/**
@@ -963,7 +958,8 @@ private void addReporter(Class<? extends IReporter> r) {
963
958
}
964
959
965
960
private void initializeDefaultListeners () {
966
- addListener ((ITestNGListener ) new ExitCodeListener (this ));
961
+ this .exitCodeListener = new org .testng .internal .ExitCodeListener ();
962
+ addListener ((ITestNGListener ) this .exitCodeListener );
967
963
if (m_useDefaultListeners ) {
968
964
addReporter (SuiteHTMLReporter .class );
969
965
addReporter (Main .class );
@@ -1155,9 +1151,9 @@ public void run() {
1155
1151
}
1156
1152
1157
1153
runExecutionListeners (false /* finish */ );
1154
+ exitCode = this .exitCodeListener .getStatus ();
1158
1155
1159
- if (!m_hasTests ) {
1160
- setStatus (HAS_NO_TEST );
1156
+ if (!exitCodeListener .hasTests ()) {
1161
1157
if (TestRunner .getVerbose () > 1 ) {
1162
1158
System .err .println ("[TestNG] No tests found. Nothing was run" );
1163
1159
usage ();
@@ -1243,7 +1239,6 @@ private void generateReports(List<ISuite> suiteRunners) {
1243
1239
*/
1244
1240
public List <ISuite > runSuitesLocally () {
1245
1241
if (m_suites .isEmpty ()) {
1246
- setStatus (HAS_NO_TEST );
1247
1242
error ("No test suite found. Nothing to run" );
1248
1243
usage ();
1249
1244
return Collections .emptyList ();
@@ -1490,7 +1485,7 @@ public static TestNG privateMain(String[] argv, ITestListener listener) {
1490
1485
else {
1491
1486
error (ex .getMessage ());
1492
1487
}
1493
- result .setStatus ( HAS_FAILURE );
1488
+ result .exitCode = ExitCode . newExitCodeRepresentingFailure ( );
1494
1489
}
1495
1490
1496
1491
return result ;
@@ -1844,21 +1839,21 @@ protected static void validateCommandLineParameters(CommandLineArgs args) {
1844
1839
* @return true if at least one test failed.
1845
1840
*/
1846
1841
public boolean hasFailure () {
1847
- return ( getStatus () & HAS_FAILURE ) == HAS_FAILURE ;
1842
+ return this . exitCode . hasFailure () ;
1848
1843
}
1849
1844
1850
1845
/**
1851
1846
* @return true if at least one test failed within success percentage.
1852
1847
*/
1853
1848
public boolean hasFailureWithinSuccessPercentage () {
1854
- return ( getStatus () & HAS_FSP ) == HAS_FSP ;
1849
+ return this . exitCode . hasFailureWithinSuccessPercentage () ;
1855
1850
}
1856
1851
1857
1852
/**
1858
1853
* @return true if at least one test was skipped.
1859
1854
*/
1860
1855
public boolean hasSkip () {
1861
- return ( getStatus () & HAS_SKIPPED ) == HAS_SKIPPED ;
1856
+ return this . exitCode . hasSkip () ;
1862
1857
}
1863
1858
1864
1859
static void exitWithError (String msg ) {
@@ -1951,30 +1946,10 @@ public static TestNG getDefault() {
1951
1946
return m_instance ;
1952
1947
}
1953
1948
1954
- /**
1955
- * @deprecated since 5.1
1956
- */
1957
- @ Deprecated
1958
- public void setHasFailure (boolean hasFailure ) {
1959
- m_status |= HAS_FAILURE ;
1960
- }
1961
-
1962
- /**
1963
- * @deprecated since 5.1
1964
- */
1965
1949
@ Deprecated
1966
- public void setHasFailureWithinSuccessPercentage (boolean hasFailureWithinSuccessPercentage ) {
1967
- m_status |= HAS_FSP ;
1968
- }
1969
-
1970
1950
/**
1971
- * @deprecated since 5.1
1951
+ * @deprecated - This class stands deprecated as of TestNG v6.13
1972
1952
*/
1973
- @ Deprecated
1974
- public void setHasSkip (boolean hasSkip ) {
1975
- m_status |= HAS_SKIPPED ;
1976
- }
1977
-
1978
1953
public static class ExitCodeListener implements IResultListener2 {
1979
1954
private TestNG m_mainRunner ;
1980
1955
@@ -1993,21 +1968,16 @@ public void beforeConfiguration(ITestResult tr) {
1993
1968
@ Override
1994
1969
public void onTestFailure (ITestResult result ) {
1995
1970
setHasRunTests ();
1996
- m_mainRunner .setStatus (HAS_FAILURE );
1997
1971
}
1998
1972
1999
1973
@ Override
2000
1974
public void onTestSkipped (ITestResult result ) {
2001
1975
setHasRunTests ();
2002
- if ((m_mainRunner .getStatus () & HAS_FAILURE ) != 0 ) {
2003
- m_mainRunner .setStatus (HAS_SKIPPED );
2004
- }
2005
1976
}
2006
1977
2007
1978
@ Override
2008
1979
public void onTestFailedButWithinSuccessPercentage (ITestResult result ) {
2009
1980
setHasRunTests ();
2010
- m_mainRunner .setStatus (HAS_FSP );
2011
1981
}
2012
1982
2013
1983
@ Override
@@ -2030,23 +2000,20 @@ public void onTestStart(ITestResult result) {
2030
2000
}
2031
2001
2032
2002
private void setHasRunTests () {
2033
- m_mainRunner .m_hasTests = true ;
2034
2003
}
2035
2004
2036
2005
/**
2037
2006
* @see org.testng.IConfigurationListener#onConfigurationFailure(org.testng.ITestResult)
2038
2007
*/
2039
2008
@ Override
2040
2009
public void onConfigurationFailure (ITestResult itr ) {
2041
- m_mainRunner .setStatus (HAS_FAILURE );
2042
2010
}
2043
2011
2044
2012
/**
2045
2013
* @see org.testng.IConfigurationListener#onConfigurationSkip(org.testng.ITestResult)
2046
2014
*/
2047
2015
@ Override
2048
2016
public void onConfigurationSkip (ITestResult itr ) {
2049
- m_mainRunner .setStatus (HAS_SKIPPED );
2050
2017
}
2051
2018
2052
2019
/**
0 commit comments