public void apply()

in scala/test-integration/test-runners/src/org/jetbrains/plugins/scala/testingSupport/scalaTest/ScalaTestReporterWithLocation.java [73:250]


    public void apply(Event event) {
        Ordinal ordinal = event.ordinal();
        if (event instanceof RunStarting) {
            RunStarting r = (RunStarting) event;
            treeBuilder.initRun(r);
            int testCount = r.testCount();
            System.out.println("\n##teamcity[testCount count='" + testCount + "']");
        } else if (event instanceof TestStarting) {
            TestStarting testStarting = ((TestStarting) event);
            String testText = testStarting.testText();
            String decodedTestText = decodeString(testText);
            String testName = testStarting.testName();
            String decodedTestName = decodeString(testName);
            String locationHint = getLocationHint(testStarting.suiteClassName(), testStarting.location(), decodedTestName);
            String message = "testStarted name='" + escapeString(decodedTestText) + "'" + locationHint +
                    " captureStandardOutput='true'";
            treeBuilder.openScope(message, ordinal, testStarting.suiteId(), true);
        } else if (event instanceof TestSucceeded) {
            TestSucceeded testSucceeded = (TestSucceeded) event;
            Option<Object> durationOption = testSucceeded.duration();
            long duration = 0;
            if (durationOption instanceof Some) {
                duration = (Long) durationOption.get();
            }
            String testText = testSucceeded.testText();
            String decodedTestText = decodeString(testText);
            String message = "testFinished name='" + escapeString(decodedTestText) +
                    "' duration='" + duration + "'";
            treeBuilder.closeScope(message, ordinal, testSucceeded.suiteId(), true);
            final String testSucceededName = "org.scalatest.events.TestSucceeded";
            collectRecordableEvents(testSucceeded, testSucceededName);
        } else if (event instanceof TestFailed) {
            boolean error = true;
            TestFailed testFailed = (TestFailed) event;
            Option<Throwable> throwableOption = testFailed.throwable();
            String detail = "";
            String failureLocation = "";
            if (throwableOption instanceof Some) {
                Throwable throwable = throwableOption.get();
                if (throwable instanceof AssertionError) error = false;
                detail = getStackTraceString(throwable);
                if (throwable instanceof StackDepthException) {
                    StackDepthException stackDepthException = (StackDepthException) throwable;

                    Option<String> fileNameAndLineNumber = stackDepthException.failedCodeFileNameAndLineNumberString();

                    int failedCodeStackDepth = stackDepthException.failedCodeStackDepth();
                    StackTraceElement[] stackTraceElements = stackDepthException.getStackTrace();
                    StackTraceElement stackTraceElement = stackTraceElements[failedCodeStackDepth];

                    String className = stackTraceElement != null ? stackTraceElement.getClassName() : null;
                    if (fileNameAndLineNumber instanceof Some && className != null) {
                        //NOTE: it's a workaround for SCL-21627 and SCL-24693.
                        //The common issue in ScalaTest is https://github.com/scalatest/scalatest/issues/2286.
                        //If the stack trace element contains "org.scalatest.Assertions" or "org.scalatest.matchers.*"
                        //we assume that Scalatest could not properly detect the original test position.
                        boolean scalaTestFailedToDetectTestSourcePosition =
                          className.equals("org.scalatest.Assertions") ||
                            className.startsWith("org.scalatest.matchers.");
                        String optionalClassPrefix = !scalaTestFailedToDetectTestSourcePosition ? className + " " : "";
                        failureLocation = "\nScalaTestFailureLocation: " + optionalClassPrefix + "at ("  + fileNameAndLineNumber.get() + ")";
                    }
                }
            }
            String testText = testFailed.testText();
            String decodedTestText = decodeString(testText);
            String message = testFailed.message() + failureLocation;
            long timeStamp = event.timeStamp();
            String res = "testFailed name='" + escapeString(decodedTestText) + "' message='" + escapeString(message) +
                    "' details='" + escapeString(detail) + "' ";
            if (error) res += "error = 'true'";
            res += TestRunnerUtil.actualExpectedAttrsScalaTest(testFailed.message());
            res += "timestamp='" + escapeString(formatTimestamp(new Date(timeStamp))) + "'";
            treeBuilder.closeScope(res, ordinal, testFailed.suiteId(), true);
            final String eventName = "org.scalatest.events.TestFailed";
            collectRecordableEvents(event, eventName);
        } else if (event instanceof TestIgnored) {
            final String ignoredTestSuffix = "!!! IGNORED !!!";
            TestIgnored testIgnored = (TestIgnored) event;
            String testText = testIgnored.testText();
            String decodedTestText = decodeString(testText);
            final String locationHint = getLocationHint(testIgnored.suiteClassName(), testIgnored.location(), decodedTestText);
            String suffixedTestText = decodedTestText + " " + ignoredTestSuffix;
            String openMessage = "testStarted name='" + escapeString(suffixedTestText) + "'" + locationHint;
            treeBuilder.openScope(openMessage, ordinal, testIgnored.suiteId(), true);
            String closeMessage = "testIgnored name='" + escapeString(suffixedTestText) + "' message='" +
                    escapeString("Test Ignored") + "'";
            treeBuilder.closeScope(closeMessage, ordinal, testIgnored.suiteId(), true);
        } else if (event instanceof TestPending) {
            TestPending testPending = (TestPending) event;
            String testText = testPending.testText();
            String decodedTestText = decodeString(testText);
            String message = "testIgnored name='" + escapeString(decodedTestText) + "' message='" +
                    escapeString("Test Pending") + "'";
            treeBuilder.closeScope(message, ordinal, testPending.suiteId(), true);
            final String eventName = "org.scalatest.events.TestPending";
            collectRecordableEvents(event, eventName);
        } else if (event instanceof TestCanceled) {
            TestCanceled testCanceled = (TestCanceled) event;
            String testText = testCanceled.testText();
            String decodedTestText = decodeString(testText);
            Option<Throwable> throwableOption = testCanceled.throwable();
            String throwableStackTrace = null;
            String errorMessage = "";
            if (throwableOption instanceof Some) {
                throwableStackTrace = "\n" + getStackTraceString(throwableOption.get());
                errorMessage = throwableOption.get().getLocalizedMessage();
                errorMessage = errorMessage == null ? "" : ": " + errorMessage;
            }
            String message = "testIgnored name='" + escapeString(decodedTestText) + "' message='" +
                    escapeString("Test Canceled" + errorMessage) + "'" +
                    (throwableStackTrace == null ? "" : " details = '" + escapeString(throwableStackTrace) + "'");
            treeBuilder.closeScope(message, ordinal, testCanceled.suiteId(), true);
            final String eventName = "org.scalatest.events.TestCancelled";
            collectRecordableEvents(event, eventName);
        } else if (event instanceof SuiteStarting) {
            SuiteStarting suiteStarting = (SuiteStarting) event;
            String suiteName = suiteStarting.suiteName();
            String locationHint = getLocationHint(suiteStarting.suiteClassName(), suiteStarting.location(), suiteName);
            String message = "testSuiteStarted name='" + escapeString(suiteName) + "'" + locationHint +
                    " captureStandardOutput='true'";
            treeBuilder.openSuite(message, suiteStarting);
        } else if (event instanceof SuiteCompleted) {
            String suiteName = ((SuiteCompleted) event).suiteName();
            String message = "testSuiteFinished name='" + escapeString(suiteName) + "'";
            treeBuilder.closeSuite(message, (SuiteCompleted) event);
        } else if (event instanceof SuiteAborted) {
            //TODO: see if not processing id stack can cause trouble on suiteAborted
            SuiteAborted suiteAborted = (SuiteAborted) event;
            String message = suiteAborted.message();
            Option<Throwable> throwableOption = suiteAborted.throwable();
            String throwableString = "";
            if (throwableOption instanceof Some) {
                throwableString = " errorDetails='" + escapeString(getStackTraceString(throwableOption.get())) + "'";
            }
            String escapedMessage = escapeString(message);
            if (!escapedMessage.isEmpty()) {
                System.out.println("\n##teamcity[message text='" + escapedMessage + "' status='ERROR'" +
                        throwableString + "]");
            }
        } else if (event instanceof InfoProvided) {
            String message = ((InfoProvided) event).message();
            String escapedMessage = escapeString(message + "\n");
            if (!escapedMessage.isEmpty()) {
                System.out.println("\n##teamcity[message text='" + escapedMessage + "' status='WARNING'" + "]");
            }
        } else if (event instanceof RunStopped) {

        } else if (event instanceof RunAborted) {
            String message = ((RunAborted) event).message();
            Option<Throwable> throwableOption = ((RunAborted) event).throwable();
            String throwableString = "";
            if (throwableOption instanceof Some) {
                throwableString = " errorDetails='" + escapeString(getStackTraceString(throwableOption.get())) + "'";
            }
            String escapedMessage = escapeString(message);
            if (!escapedMessage.isEmpty()) {
                System.out.println("\n##teamcity[message text='" + escapedMessage + "' status='ERROR'" + throwableString + "]");
                runAborted = true;
            }
        } else if (event instanceof RunCompleted) {

        } else if (event instanceof ScopeOpened) {
            ScopeOpened scopeOpened = (ScopeOpened) event;
            String message = scopeOpened.message();
            String locationHint = getLocationHint(scopeOpened.nameInfo().suiteClassName(), scopeOpened.location(), message);
            String tcMessage = "testSuiteStarted name='" + escapeString(message) + "'" + locationHint +
                    " captureStandardOutput='true'";
            treeBuilder.openScope(tcMessage, ordinal, scopeOpened.nameInfo().suiteId(), false);
        } else if (event instanceof ScopeClosed) {
            String message = ((ScopeClosed) event).message();
            String tcMessage = "testSuiteFinished name='" + escapeString(message) + "'";
            treeBuilder.closeScope(tcMessage, ordinal, ((ScopeClosed) event).nameInfo().suiteId(), false);
        } else if (event instanceof ScopePending) {
            String message = ((ScopePending) event).message();
            treeBuilder.closePendingScope(message, ordinal, ((ScopePending) event).nameInfo().suiteId());
        }
    }