2929import org .testng .internal .ClassHelper ;
3030import org .testng .internal .Configuration ;
3131import org .testng .internal .DynamicGraph ;
32+ import org .testng .internal .ExitCode ;
3233import org .testng .internal .IConfiguration ;
3334import org .testng .internal .IResultListener2 ;
3435import org .testng .internal .OverrideProcessor ;
@@ -142,16 +143,9 @@ public class TestNG {
142143 private final Map <Class <? extends IReporter >, IReporter > m_reporters = Maps .newHashMap ();
143144 private final Map <Class <? extends IDataProviderListener >, IDataProviderListener > m_dataProviderListeners = Maps .newHashMap ();
144145
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 ;
149146
150147 public static final Integer DEFAULT_VERBOSE = 1 ;
151148
152- private int m_status ;
153- private boolean m_hasTests = false ;
154-
155149 // Command line suite parameters
156150 private int m_threadCount = -1 ;
157151 private XmlSuite .ParallelMode m_parallelMode = null ;
@@ -185,6 +179,8 @@ public class TestNG {
185179 private final Map <Class <? extends IAlterSuiteListener >, IAlterSuiteListener > m_alterSuiteListeners = Maps .newHashMap ();
186180
187181 private boolean m_isInitialized = false ;
182+ private org .testng .internal .ExitCodeListener exitCodeListener ;
183+ private ExitCode exitCode ;
188184
189185 /**
190186 * Default constructor. Setting also usage of default listeners/reporters.
@@ -211,11 +207,10 @@ private void init(boolean useDefaultListeners) {
211207 }
212208
213209 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 ();
219214 }
220215
221216 /**
@@ -963,7 +958,8 @@ private void addReporter(Class<? extends IReporter> r) {
963958 }
964959
965960 private void initializeDefaultListeners () {
966- addListener ((ITestNGListener ) new ExitCodeListener (this ));
961+ this .exitCodeListener = new org .testng .internal .ExitCodeListener ();
962+ addListener ((ITestNGListener ) this .exitCodeListener );
967963 if (m_useDefaultListeners ) {
968964 addReporter (SuiteHTMLReporter .class );
969965 addReporter (Main .class );
@@ -1155,9 +1151,9 @@ public void run() {
11551151 }
11561152
11571153 runExecutionListeners (false /* finish */ );
1154+ exitCode = this .exitCodeListener .getStatus ();
11581155
1159- if (!m_hasTests ) {
1160- setStatus (HAS_NO_TEST );
1156+ if (!exitCodeListener .hasTests ()) {
11611157 if (TestRunner .getVerbose () > 1 ) {
11621158 System .err .println ("[TestNG] No tests found. Nothing was run" );
11631159 usage ();
@@ -1243,7 +1239,6 @@ private void generateReports(List<ISuite> suiteRunners) {
12431239 */
12441240 public List <ISuite > runSuitesLocally () {
12451241 if (m_suites .isEmpty ()) {
1246- setStatus (HAS_NO_TEST );
12471242 error ("No test suite found. Nothing to run" );
12481243 usage ();
12491244 return Collections .emptyList ();
@@ -1490,7 +1485,7 @@ public static TestNG privateMain(String[] argv, ITestListener listener) {
14901485 else {
14911486 error (ex .getMessage ());
14921487 }
1493- result .setStatus ( HAS_FAILURE );
1488+ result .exitCode = ExitCode . newExitCodeRepresentingFailure ( );
14941489 }
14951490
14961491 return result ;
@@ -1844,21 +1839,21 @@ protected static void validateCommandLineParameters(CommandLineArgs args) {
18441839 * @return true if at least one test failed.
18451840 */
18461841 public boolean hasFailure () {
1847- return ( getStatus () & HAS_FAILURE ) == HAS_FAILURE ;
1842+ return this . exitCode . hasFailure () ;
18481843 }
18491844
18501845 /**
18511846 * @return true if at least one test failed within success percentage.
18521847 */
18531848 public boolean hasFailureWithinSuccessPercentage () {
1854- return ( getStatus () & HAS_FSP ) == HAS_FSP ;
1849+ return this . exitCode . hasFailureWithinSuccessPercentage () ;
18551850 }
18561851
18571852 /**
18581853 * @return true if at least one test was skipped.
18591854 */
18601855 public boolean hasSkip () {
1861- return ( getStatus () & HAS_SKIPPED ) == HAS_SKIPPED ;
1856+ return this . exitCode . hasSkip () ;
18621857 }
18631858
18641859 static void exitWithError (String msg ) {
@@ -1951,30 +1946,10 @@ public static TestNG getDefault() {
19511946 return m_instance ;
19521947 }
19531948
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- */
19651949 @ Deprecated
1966- public void setHasFailureWithinSuccessPercentage (boolean hasFailureWithinSuccessPercentage ) {
1967- m_status |= HAS_FSP ;
1968- }
1969-
19701950 /**
1971- * @deprecated since 5.1
1951+ * @deprecated - This class stands deprecated as of TestNG v6.13
19721952 */
1973- @ Deprecated
1974- public void setHasSkip (boolean hasSkip ) {
1975- m_status |= HAS_SKIPPED ;
1976- }
1977-
19781953 public static class ExitCodeListener implements IResultListener2 {
19791954 private TestNG m_mainRunner ;
19801955
@@ -1993,21 +1968,16 @@ public void beforeConfiguration(ITestResult tr) {
19931968 @ Override
19941969 public void onTestFailure (ITestResult result ) {
19951970 setHasRunTests ();
1996- m_mainRunner .setStatus (HAS_FAILURE );
19971971 }
19981972
19991973 @ Override
20001974 public void onTestSkipped (ITestResult result ) {
20011975 setHasRunTests ();
2002- if ((m_mainRunner .getStatus () & HAS_FAILURE ) != 0 ) {
2003- m_mainRunner .setStatus (HAS_SKIPPED );
2004- }
20051976 }
20061977
20071978 @ Override
20081979 public void onTestFailedButWithinSuccessPercentage (ITestResult result ) {
20091980 setHasRunTests ();
2010- m_mainRunner .setStatus (HAS_FSP );
20111981 }
20121982
20131983 @ Override
@@ -2030,23 +2000,20 @@ public void onTestStart(ITestResult result) {
20302000 }
20312001
20322002 private void setHasRunTests () {
2033- m_mainRunner .m_hasTests = true ;
20342003 }
20352004
20362005 /**
20372006 * @see org.testng.IConfigurationListener#onConfigurationFailure(org.testng.ITestResult)
20382007 */
20392008 @ Override
20402009 public void onConfigurationFailure (ITestResult itr ) {
2041- m_mainRunner .setStatus (HAS_FAILURE );
20422010 }
20432011
20442012 /**
20452013 * @see org.testng.IConfigurationListener#onConfigurationSkip(org.testng.ITestResult)
20462014 */
20472015 @ Override
20482016 public void onConfigurationSkip (ITestResult itr ) {
2049- m_mainRunner .setStatus (HAS_SKIPPED );
20502017 }
20512018
20522019 /**
0 commit comments