<commit_before>import ceylon.language.meta {
    modules
}
import ceylon.test {
    createTestRunner,
    TestSource,
    SimpleLoggingListener,
    TestListener,
    TestRunResult
}
import com.redhat.ceylon.test.eclipse {
    TestEventPublisher,
    Util {
        createSocket,
        createObjectOutputStream,
        setColor
    }
}
import java.io {
    ObjectOutputStream,
    IOException
}
import java.lang {
    Thread,
    InterruptedException
}
import java.net {
    Socket
}
import org.jboss.modules {
    Module {
        ceylonModuleLoader=callerModuleLoader
    },
    ModuleIdentifier {
        createModuleIdentifier=create
    },
    ModuleClassLoader
}

shared void run() {
    Runner().run();
}

class Runner() {

    value moduleNameAndVersions = SequenceBuilder<[String, String]>();
    value testSources = SequenceBuilder<TestSource>();
    variable Integer port = -1;
    variable Socket? socket = null;
    variable ObjectOutputStream? oos = null;

    shared void run() {
        try {
            init();
            loadModules();
            connect();
            
            if( testSources.empty ) {
                for(value moduleNameAndVersion in moduleNameAndVersions.sequence) {
                    assert(exists m = modules.find(moduleNameAndVersion[0], moduleNameAndVersion[1]));
                    testSources.append(m);
                }
            }

            TestListener[] testListeners;
            if( exists o = oos ) {
                testListeners = [TestEventPublisher(o)];
            }
            else {
                object loggingListener extends SimpleLoggingListener() {

                    value colorCodeRed = 1;
                    value colorCodeGreen = 2;
                    value colorCodeWhite = 7;

                    shared actual void writeBannerSuccess(TestRunResult result) {
                        setColor(colorCodeGreen);
                        try {
                            super.writeBannerSuccess(result);
                        }
                        finally {
                            setColor(colorCodeWhite);
                        }
                    }

                    shared actual void writeBannerFailed(TestRunResult result) {
                        setColor(colorCodeRed);
                        try {
                            super.writeBannerFailed(result);
                        }
                        finally {
                            setColor(colorCodeWhite);
                        }
                    }

                }
                testListeners = [loggingListener];
            }

            createTestRunner(testSources.sequence, testListeners).run();
        }
        finally {
            disconnect();
        }
    }

    void init() {
        variable String prev = "";

        for(String arg in process.arguments) {
            if( prev == "--module" ) {
                assert(exists i = arg.firstInclusion("/"));
                String moduleName = arg[0..i-1];
                String moduleVersion = arg[i+1...];
                
                moduleNameAndVersions.append([moduleName, moduleVersion]);
            }
            if( prev == "--test" ) {
                testSources.append(arg);
            }
            if( arg.startsWith("--port") ) {
                assert(exists p = parseInteger(arg[7...]));
                port = p;
            }<commit_msg>ceylon.test: add --tap option for TapLoggingListener<commit_after>import ceylon.language.meta {
    modules
}
import ceylon.test {
    createTestRunner,
    TestSource,
    SimpleLoggingListener,
    TapLoggingListener,
    TestListener,
    TestRunResult
}
import com.redhat.ceylon.test.eclipse {
    TestEventPublisher,
    Util {
        createSocket,
        createObjectOutputStream,
        setColor
    }
}
import java.io {
    ObjectOutputStream,
    IOException
}
import java.lang {
    Thread,
    InterruptedException
}
import java.net {
    Socket
}
import org.jboss.modules {
    Module {
        ceylonModuleLoader=callerModuleLoader
    },
    ModuleIdentifier {
        createModuleIdentifier=create
    },
    ModuleClassLoader
}

shared void run() {
    Runner().run();
}

class Runner() {

    object loggingListener extends SimpleLoggingListener() {
        
        value colorCodeRed = 1;
        value colorCodeGreen = 2;
        value colorCodeWhite = 7;
        
        shared actual void writeBannerSuccess(TestRunResult result) {
            setColor(colorCodeGreen);
            try {
                super.writeBannerSuccess(result);
            }
            finally {
                setColor(colorCodeWhite);
            }
        }
        
        shared actual void writeBannerFailed(TestRunResult result) {
            setColor(colorCodeRed);
            try {
                super.writeBannerFailed(result);
            }
            finally {
                setColor(colorCodeWhite);
            }
        }
        
    }

    value moduleNameAndVersions = SequenceBuilder<[String, String]>();
    value testSources = SequenceBuilder<TestSource>();
    variable TestListener defaultTestListener = loggingListener;
    variable Integer port = -1;
    variable Socket? socket = null;
    variable ObjectOutputStream? oos = null;

    shared void run() {
        try {
            init();
            loadModules();
            connect();
            
            if( testSources.empty ) {
                for(value moduleNameAndVersion in moduleNameAndVersions.sequence) {
                    assert(exists m = modules.find(moduleNameAndVersion[0], moduleNameAndVersion[1]));
                    testSources.append(m);
                }
            }

            TestListener[] testListeners;
            if( exists o = oos ) {
                testListeners = [TestEventPublisher(o)];
            }
            else {
                testListeners = [defaultTestListener];
            }

            createTestRunner(testSources.sequence, testListeners).run();
        }
        finally {
            disconnect();
        }
    }

    void init() {
        variable String prev = "";

        for(String arg in process.arguments) {
            if( prev == "--module" ) {
                assert(exists i = arg.firstInclusion("/"));
                String moduleName = arg[0..i-1];
                String moduleVersion = arg[i+1...];
                
                moduleNameAndVersions.append([moduleName, moduleVersion]);
            }
            if( prev == "--test" ) {
                testSources.append(arg);
            }
            if( arg.startsWith("--port") ) {
                assert(exists p = parseInteger(arg[7...]));
                port = p;
            }
            if( arg == "--tap") {
                defaultTestListener = TapLoggingListener();
            }
{'fraction_non_alphanumeric': 0.08947598890672895, 'fraction_numerical': 0.002919281856663261, 'mean_word_length': 1.4462691895751518, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '661455', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1651, 'n_words': 335}