kotlin-samples-verifier

A library that extracts embedded code snippets from HTML and Markdown files from a remote git repository, runs them and collects results.

License

License

Categories

Categories

Kotlin Languages
GroupId

GroupId

io.github.alexanderprendota
ArtifactId

ArtifactId

kotlin-samples-verifier
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

kotlin-samples-verifier
A library that extracts embedded code snippets from HTML and Markdown files from a remote git repository, runs them and collects results.
Project URL

Project URL

https://github.com/AlexanderPrendota/kotlin-samples-verifier
Source Code Management

Source Code Management

https://github.com/AlexanderPrendota/kotlin-samples-verifier

Download kotlin-samples-verifier

Dependencies

runtime (13)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.3.70
com.vladsch.flexmark : flexmark-all jar 0.62.2
org.jsoup : jsoup jar 1.13.1
org.eclipse.jgit : org.eclipse.jgit jar 5.10.0.202012080955-r
org.apache.directory.studio : org.apache.commons.io jar 2.4
com.squareup.retrofit2 : retrofit jar 2.9.0
com.squareup.retrofit2 : converter-jaxb jar 2.9.0
com.squareup.retrofit2 : converter-jackson jar 2.9.0
com.fasterxml.jackson.module : jackson-module-kotlin jar 2.12.3
com.squareup.okhttp3 : okhttp jar 4.9.1
com.github.h0tk3y.betterParse : better-parse-jvm jar 0.4.2
org.slf4j : slf4j-api jar 2.0.0-alpha1
org.slf4j : slf4j-log4j12 jar 2.0.0-alpha1

Project Modules

There are no modules declared in this project.

Kotlin samples verifier

Java CI with Gradle

Kotlin documentation testing tool.

A library that extracts embedded code snippets from HTML and Markdown files from a remote git repository, runs them and collects results.

Setup

Execution

Check and Collect send calls to kotlin-compiler-server to execute code, URL is passed as an argument to the factory create method and set to http://localhost:8080/ by default.

Gradle tasks to run server using docker:

  • Pull server docker image and start it as a docker container:
./gradlew dockerRun
  • Stop and remove docker container:
./gradlew dockerStop dockerRemoveContainer

Also, the tool can collect snippets from the changes between two commits or two branches.

Gradle

Maven Central:

dependencies {
    ...
    implementation("io.github.alexanderprendota:kotlin-samples-verifier:1.1.4:1.1.0")
}

Console Client

  • Download Kotlin dependencies and build project:
./gradlew build -x test
./gradlew installDist

Options:

Name (alias) Format Description Default
-snippet-flags (-f) [String[,]] Flags for code snippets, separated by "," like so: "attr1,attr2" n/a
-ignore-attributes [String[,]] Attributes (name and value separated by \":\" (name:value)) for code snippets to ignore, separated by \",\" like so: \"attr1,attr2\" null
-parse-directory [String] Regexp for directories to be processed null
-ignore-directory [String] Regexp for directories to be ignored null
-parse-tags [String[,]] Html tags to be accepted as code snippets, works for both html and md. Default (code) for MD so only fencedCodeBlocks are accepted as code snippets null
-compiler-url [String] Kotlin compiler URL http://localhost:8080/
-commits [String [,String]] Considering only the changed files between two arbitrary commits "commit1,commit2" or starting from "commit1" if "commit2" on one side is omitted null
-file-type [FileType] MD or HTML (type of files to be processed) MD
-kotlin-env [KotlinEnv] JS or JVM JVM
-repository (-r) [String] Git repository URL with samples to execute n/a
-tag-filter [String] User filter for tag containing snippet like so: (#tag="name" & attr1="val"). It also supports !, &, / operations ""
-ignore-tag-filter [String] User filter for ignoring of tag including inners tags ""

Only for collect:

Name (alias) Format Description Default
-out (-o) [String] Filename to store results n/a

Example:

./client/build/install/client/bin/client check -r https://github.com/AlexanderPrendota/kotlin-samples-verifier.git -f run-kotlin

Usage Example

val samplesVerifier = SamplesVerifierFactory.create().configure {
  snippetFlags = hashSetOf("run-kotlin")
  ignoreAttributes = hashSetOf(Attribute("data-highlight-only", ""))
  parseTags = hashSetOf("code", "div")
}

val repositoryURL = "https://github.com/AlexanderPrendota/kotlin-samples-verifier.git"

// log execution results

samplesVerifier.check(repositoryURL, "master", FileType.MD)

// get results as Map<ExecutionResult, Code>

val results = samplesVerifier.collect(repositoryURL, "master", FileType.MD)

// process files from list

val filenames = listOf<String>(...)

val results2 = samplesVerifier.collect(filenames, FileType.MD)

Versions

Version
1.1.0