/*
 * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
 */

package org.jetbrains.kotlin.konan.test.blackbox.support.util

import org.jetbrains.kotlin.konan.test.blackbox.buildDir
import java.io.File
import java.io.FileWriter

fun createTestProvider(parentDirectory: File, testSources: List<File>): File {
    // create a test provider and get main entry point
    val provider = parentDirectory.resolve("provider.swift")
    FileWriter(provider).use { writer ->
        val providers = testSources
            .map { file ->
                file.name.toString().removeSuffix(".swift").replaceFirstChar { it.uppercase() }
            }
            .map { "${it}Tests" }

        writer.write(
            """
                |// THIS IS AUTOGENERATED FILE
                |// This method is invoked by the main routine to get a list of tests
                |func registerProviders() {
                |    ${providers.joinToString("\n    ") { "$it()" }}
                |}
                """.trimMargin()
        )
    }
    return provider
}