Skip to content

Commit

Permalink
Merge pull request #6 from koperagen/test-results
Browse files Browse the repository at this point in the history
Hack for displaying snippet outputs in dataframe project
  • Loading branch information
devcrocod authored May 2, 2023
2 parents 2dd5d55 + f078a62 commit 4ff4199
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ kotlin_version=1.8.20
language_version=1.8
dokka_version=1.8.10
pluginPublishVersion=0.15.0
org.gradle.jvmargs=-Xmx2G
9 changes: 8 additions & 1 deletion src/main/kotlin/io/github/devcrocod/korro/Korro.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fun KorroContext.korro(inputFile: File): Boolean {
it + funName
}
val newSamplesLines = functionNames.firstNotNullOfOrNull { name -> // TODO: can be improved
val text = samplesTransformer(name) ?: groups.firstNotNullOfOrNull { group ->
var text = samplesTransformer(name) ?: groups.firstNotNullOfOrNull { group ->
group.patterns.mapNotNull { pattern ->
samplesTransformer(name + pattern.nameSuffix)?.let {
group.beforeSample?.let { pattern.processSubstitutions(it) } + it +
Expand All @@ -44,6 +44,12 @@ fun KorroContext.korro(inputFile: File): Boolean {
postfix = group.afterGroup ?: ""
)
}

val output = outputsMap[name]
if (text != null && output != null) {
text += output.readText()
}

text?.split("\n")?.plus(END_SAMPLE) //?: oldSampleLines
}
if (newSamplesLines == null) {
Expand Down Expand Up @@ -136,6 +142,7 @@ fun KorroContext.korroClean(inputFile: File): Boolean {
when(nextDir?.name) {
END_DIRECTIVE -> {
oldSampleLines.add(sampleLine)
lines.add(sampleLine)
break
}
EOF, FUN_DIRECTIVE -> {
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/io/github/devcrocod/korro/KorroAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import java.io.File
interface KorroParameters : WorkParameters {
var docs: Set<File>
var samples: Set<File>
var outputs: Set<File>
var groups: List<SamplesGroup>
var name: String
}
Expand All @@ -20,7 +21,7 @@ abstract class KorroAction : WorkAction<KorroParameters> {

override fun execute() {
ext.groups.addAll(parameters.groups)
val ctx = ext.createContext(parameters.docs, parameters.samples)
val ctx = ext.createContext(parameters.docs, parameters.samples, parameters.outputs)

//TODO - check missing files!

Expand All @@ -41,7 +42,7 @@ abstract class KorroCleanAction : WorkAction<KorroParameters> {
abstract val ext: KorroExtension

override fun execute() {
val ctx = ext.createContext(parameters.docs, parameters.samples)
val ctx = ext.createContext(parameters.docs, parameters.samples, parameters.outputs)

if (!ctx.processClean()) {
val extra = if (ctx.logger.nOutdated > 0)
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/io/github/devcrocod/korro/KorroContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ class KorroContext(
val logger: KorroLog,
docs: Collection<File>,
samples: Collection<File>,
outputs: Collection<File>,
val groups: List<SamplesGroup>
) {
// state
val fileQueue = ArrayDeque(docs)
val sampleSet = HashSet(samples)
val outputsMap = outputs.associateBy { it.name }
}

fun KorroContext.process(): Boolean {
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/io/github/devcrocod/korro/KorroExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ abstract class GroupSamplesApi {
abstract class KorroExtension {
var docs: FileCollection? = null
var samples: FileCollection? = null
var outputs: FileCollection? = null

internal val groups = mutableListOf<SamplesGroup>()

Expand All @@ -61,10 +62,11 @@ abstract class KorroExtension {
groups.add(group)
}

fun createContext(docs: Collection<File>, samples: Collection<File>) = KorroContext(
fun createContext(docs: Collection<File>, samples: Collection<File>, outputs: Collection<File>) = KorroContext(
logger = LoggerLog(),
docs = docs,
samples = samples,
outputs = outputs,
groups = groups
)
}
9 changes: 9 additions & 0 deletions src/main/kotlin/io/github/devcrocod/korro/KorroTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ private interface KorroTasksCommon {

var samples: FileCollection

var outputs: FileCollection

@get:Internal
val groups: List<SamplesGroup>

Expand All @@ -53,6 +55,7 @@ private interface KorroTasksCommon {
workQueue.submit(clazz) {
it.docs = docs.files
it.samples = samples.files
it.outputs = outputs.files
it.groups = groups
it.name = nameReference
}
Expand All @@ -73,6 +76,9 @@ abstract class KorroTask : DefaultTask(), KorroTasksCommon {
it.include("**/*.kt")
}

@InputFiles
override var outputs: FileCollection = ext.outputs ?: project.files()

@get:Internal
override val groups: List<SamplesGroup> = ext.groups

Expand Down Expand Up @@ -103,6 +109,9 @@ abstract class KorroCleanTask : Delete(), KorroTasksCommon {
it.include("**/*.kt")
}

@InputFiles
override var outputs: FileCollection = ext.outputs ?: project.files()

@get:Internal
override val groups: List<SamplesGroup> = ext.groups

Expand Down

0 comments on commit 4ff4199

Please sign in to comment.