<commit_before>package decompose

import com.github.salomonbrys.kodein.Kodein
import com.github.salomonbrys.kodein.bind
import com.github.salomonbrys.kodein.instance
import com.natpryce.hamkrest.assertion.assert
import com.natpryce.hamkrest.equalTo
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.reset
import com.nhaarman.mockito_kotlin.whenever
import decompose.cli.Command
import decompose.cli.CommandLineParser
import decompose.cli.Failed
import decompose.cli.Succeeded
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import java.io.ByteArrayOutputStream
import java.io.PrintStream

object ApplicationSpec : Spek({
    describe("an application") {
        val errorStream = ByteArrayOutputStream()
        val commandLineParser = mock<CommandLineParser>()

        val dependencies = Kodein {
            bind<PrintStream>(PrintStreamType.Error) with instance(PrintStream(errorStream))
            bind<CommandLineParser>() with instance(commandLineParser)
        }

        val application = Application(dependencies)
        val args = listOf("some-command", "some-param")

        beforeEachTest {
            errorStream.reset()

            reset(commandLineParser)
        }

        given("the command line parser returns a command") {
            val command = object : Command {
                override fun run(): Int = 123
            }

            on("running the application") {
                whenever(commandLineParser.parse(args)).thenReturn(Succeeded(command))

                val exitCode = application.run(args)

                it("does not print anything to the error stream") {
                    assert.that(errorStream.toString(), equalTo(""))
                }

                it("returns the exit code from the command") {
                    assert.that(exitCode, equalTo(123))
                }
            }
        }

        given("the command line parser returns an error") {
            on("running the application") {
                whenever(commandLineParser.parse(args)).thenReturn(Failed("Something went wrong while parsing arguments"))

                val exitCode = application.run(args)

                it("prints the error message to the error stream") {
                    assert.that(errorStream.toString(), equalTo("Something went wrong while parsing arguments\n"))
                }

                it("returns a non-zero exit code") {
                    assert.that(exitCode, !equalTo(0))
                }
            }
        }
    }
})<commit_msg>Add two missing test cases.<commit_after>package decompose

import com.github.salomonbrys.kodein.Kodein
import com.github.salomonbrys.kodein.bind
import com.github.salomonbrys.kodein.instance
import com.natpryce.hamkrest.assertion.assert
import com.natpryce.hamkrest.containsSubstring
import com.natpryce.hamkrest.equalTo
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.reset
import com.nhaarman.mockito_kotlin.whenever
import decompose.cli.Command
import decompose.cli.CommandLineParser
import decompose.cli.Failed
import decompose.cli.Succeeded
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import java.io.ByteArrayOutputStream
import java.io.PrintStream

object ApplicationSpec : Spek({
    describe("an application") {
        val errorStream = ByteArrayOutputStream()
        val commandLineParser = mock<CommandLineParser>()

        val dependencies = Kodein {
            bind<PrintStream>(PrintStreamType.Error) with instance(PrintStream(errorStream))
            bind<CommandLineParser>() with instance(commandLineParser)
        }

        val application = Application(dependencies)
        val args = listOf("some-command", "some-param")

        beforeEachTest {
            errorStream.reset()

            reset(commandLineParser)
        }

        given("the command line parser returns a command") {
            on("running the application") {
                val command = object : Command {
                    override fun run(): Int = 123
                }

                whenever(commandLineParser.parse(args)).thenReturn(Succeeded(command))

                val exitCode = application.run(args)

                it("does not print anything to the error stream") {
                    assert.that(errorStream.toString(), equalTo(""))
                }

                it("returns the exit code from the command") {
                    assert.that(exitCode, equalTo(123))
                }
            }
        }

        given("the command line parser returns an error") {
            on("running the application") {
                whenever(commandLineParser.parse(args)).thenReturn(Failed("Something went wrong while parsing arguments"))

                val exitCode = application.run(args)

                it("prints the error message to the error stream") {
                    assert.that(errorStream.toString(), equalTo("Something went wrong while parsing arguments\n"))
                }

                it("returns a non-zero exit code") {
                    assert.that(exitCode, !equalTo(0))
                }
            }
        }

        given("the command line parser throws an exception") {
            on("running the application") {
                whenever(commandLineParser.parse(args)).thenThrow(RuntimeException("Everything is broken"))

                val exitCode = application.run(args)

                it("prints the exception message to the error stream") {
                    assert.that(errorStream.toString(), containsSubstring("Everything is broken"))
                }

                it("returns a non-zero exit code") {
                    assert.that(exitCode, !equalTo(0))
                }
            }
        }

        given("the command throws an exception") {
            on("running the application") {
                val command = object : Command {
                    override fun run(): Int = throw RuntimeException("Everything is broken")
                }

                whenever(commandLineParser.parse(args)).thenReturn(Succeeded(command))

                val exitCode = application.run(args)

                it("prints the exception message to the error stream") {
                    assert.that(errorStream.toString(), containsSubstring("Everything is broken"))
                }

                it("returns a non-zero exit code") {
                    assert.that(exitCode, !equalTo(0))
                }
            }
        }
    }
})
{'fraction_non_alphanumeric': 0.09215368761960842, 'fraction_numerical': 0.00235536581775357, 'mean_word_length': 2.1673659673659675, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '7140763', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1697, 'n_words': 390}