Skip to content

Improve cross-platform static file reading in tests #660

@peterkos

Description

@peterkos

Hello!

Been using 0.24.alpha-5, and it doesn't appear possible to readText() when running a unit test via iOS in KMP. FileResource requires a context, but it's been tricky to implement this.

There's a similar library kotlinx-resources that implements this for text files:

/*
 * For Apple platforms, move resources into the binary's output directory so that they
 * can be loaded using `NSBundle.mainBundle` and related APIs.
 */
if (isAppleCompilation(kotlinCompilation)) {
    val target = kotlinCompilation.target
    target.binaries.forEach { binary ->
        setupCopyResourcesTask(
            kotlinCompilation = kotlinCompilation,
            taskName = getTaskName("copyResources", binary.name, target.targetName),
            outputDir = binary.outputDirectory,
            mustRunAfterTasks = listOf(kotlinCompilation.processResourcesTaskName),
            dependantTasks = listOf(binary.linkTaskName)
        )
    }
}

Would be cool to have something similar here! 🚀

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions