<commit_before>﻿namespace Fixie.Internal.Listeners
{
    using System;
    using System.Collections.Generic;
    using Internal;
    using static System.Environment;

    class ConsoleListener :
        Handler<CaseSkipped>,
        Handler<CasePassed>,
        Handler<CaseFailed>,
        Handler<AssemblyCompleted>
    {
        readonly bool outputCasePassed;

        internal static ConsoleListener Create()
            => new ConsoleListener(GetEnvironmentVariable("FIXIE:TESTS") != null);

        public ConsoleListener(bool outputCasePassed = false)
            => this.outputCasePassed = outputCasePassed;

        public void Handle(CaseSkipped message)
        {
            var hasReason = message.Reason != null;

            using (Foreground.Yellow)
                Console.WriteLine($"Test '{message.Name}' skipped{(hasReason ? ":" : null)}");

            if (hasReason)
                Console.WriteLine($"{message.Reason}");

            Console.WriteLine();
        }

        public void Handle(CasePassed message)
        {
            if (outputCasePassed)
            {
                using (Foreground.Green)
                    Console.WriteLine($"Test '{message.Name}' passed");

                Console.WriteLine();
            }
        }

        public void Handle(CaseFailed message)
        {
            using (Foreground.Red)
                Console.WriteLine($"Test '{message.Name}' failed:");
            Console.WriteLine();
            Console.WriteLine(message.Exception.Message);
            Console.WriteLine();
            Console.WriteLine(message.Exception.GetType().FullName);
            Console.WriteLine(message.Exception.LiterateStackTrace());
            Console.WriteLine();<commit_msg>Use whitespace in addition to color coding to call out skipped and failed tests, so that they stand out clearly in build logs or at the command line, without needlessly padding every 'Passed' test when using the --tests flag.<commit_after>﻿namespace Fixie.Internal.Listeners
{
    using System;
    using System.Collections.Generic;
    using Internal;
    using static System.Environment;

    class ConsoleListener :
        Handler<CaseSkipped>,
        Handler<CasePassed>,
        Handler<CaseFailed>,
        Handler<AssemblyCompleted>
    {
        readonly bool outputCasePassed;
        bool paddingWouldRequireOpeningBlankLine;

        internal static ConsoleListener Create()
            => new ConsoleListener(GetEnvironmentVariable("FIXIE:TESTS") != null);

        public ConsoleListener(bool outputCasePassed = false)
            => this.outputCasePassed = outputCasePassed;

        public void Handle(CaseSkipped message)
        {
            var hasReason = message.Reason != null;

            WithPadding(() =>
            {
                using (Foreground.Yellow)
                    Console.WriteLine($"Test '{message.Name}' skipped{(hasReason ? ":" : null)}");

                if (hasReason)
                    Console.WriteLine($"{message.Reason}");
            });
        }

        public void Handle(CasePassed message)
        {
            if (outputCasePassed)
            {
                WithoutPadding(() =>
                {
                    using (Foreground.Green)
                        Console.WriteLine($"Test '{message.Name}' passed");
                });
            }
        }

        public void Handle(CaseFailed message)
        {
            WithPadding(() =>
            {
                using (Foreground.Red)
                    Console.WriteLine($"Test '{message.Name}' failed:");
                Console.WriteLine();
                Console.WriteLine(message.Exception.Message);
                Console.WriteLine();
                Console.WriteLine(message.Exception.GetType().FullName);
                Console.WriteLine(message.Exception.LiterateStackTrace());
            });
        }

        void WithPadding(Action write)
        {
            if (paddingWouldRequireOpeningBlankLine)
                Console.WriteLine();

            write();
            
            Console.WriteLine();
            paddingWouldRequireOpeningBlankLine = false;
        }

        void WithoutPadding(Action write)
        {
            write();
            paddingWouldRequireOpeningBlankLine = true;
{'fraction_non_alphanumeric': 0.095559172285515, 'fraction_numerical': 0.0, 'mean_word_length': 1.8377308707124012, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7581845', 'n_tokens_mistral': 1023, 'n_tokens_neox': 971, 'n_words': 211}