Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update shell library #407

Draft
wants to merge 6 commits into
base: kscript_4.3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
version: 1.7.21

- name: Setup Gradle
uses: gradle/gradle-build-action@v2.4.2
uses: gradle/gradle-build-action@v2
with:
gradle-version: 8.0.2

Expand All @@ -64,23 +64,25 @@ jobs:

echo "OsType: $OSTYPE"

gradle clean assemble test || { echo 'Compilation or Unit tests failed' ; exit 1; }
chmod +x ./gradlew

./gradlew clean assemble test || { echo 'Compilation or Unit tests failed' ; exit 1; }

if [[ "$OSTYPE" == "linux"* ]]; then
echo "Linux test..."
gradle -DosType=$OSTYPE -DincludeTags='posix | linux' integrationTest
./gradlew -DosType=$OSTYPE -DincludeTags='posix | linux' integrationTest
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "MacOs test..."
gradle -DosType=$OSTYPE -DincludeTags='posix | macos' integrationTest
./gradlew -DosType=$OSTYPE -DincludeTags='posix | macos' integrationTest
elif [[ "$OSTYPE" == "cygwin" ]]; then
echo "Cygwin test..."
gradle -DosType=$OSTYPE -DincludeTags='posix | cygwin' integrationTest
./gradlew -DosType=$OSTYPE -DincludeTags='posix | cygwin' integrationTest
elif [[ "$OSTYPE" == "msys" ]]; then
echo "MSys test..."
gradle -DosType=$OSTYPE -DincludeTags='posix | msys' integrationTest
./gradlew -DosType=$OSTYPE -DincludeTags='posix | msys' integrationTest
elif [[ "$OSTYPE" == "freebsd"* ]]; then
echo "FreeBsd test..."
gradle -DosType=$OSTYPE -DincludeTags='posix' integrationTest
./gradlew -DosType=$OSTYPE -DincludeTags='posix' integrationTest
else
echo "Unknown OS"
exit 1
Expand All @@ -91,7 +93,7 @@ jobs:
shell: cmd
run: |
echo "Windows test..."
gradle -DosType=windows -DincludeTags="windows" clean assemble test integrationTest
.\gradlew -DosType=windows -DincludeTags="windows" clean assemble test integrationTest

- name: Install Cygwin (only Windows)
if: matrix.variant == 'cygwin'
Expand All @@ -105,5 +107,5 @@ jobs:
echo "Cygwin test..."
echo "Changing directory to $GITHUB_WORKSPACE ..."
cd $GITHUB_WORKSPACE
gradle clean assemble test || { echo 'Compilation or Unit tests failed' ; exit 1; }
gradle -DosType=$OSTYPE -DincludeTags='posix | cygwin' integrationTest
./gradlew clean assemble test || { echo 'Compilation or Unit tests failed' ; exit 1; }
./gradlew -DosType=$OSTYPE -DincludeTags='posix | cygwin' integrationTest
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ dependencies {
implementation("com.konghq:unirest-java:3.14.2")

implementation("net.igsoft:tablevis:0.6.0")
implementation("io.github.kscripting:shell:0.5.2")
implementation("io.github.kscripting:shell:0.6.0-SNAPSHOT")
implementation("io.github.kscripting:shell:0.6.0-SNAPSHOT:test")

implementation("org.slf4j:slf4j-nop:2.0.7")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package io.github.kscripting.kscript.integration

import io.github.kscripting.kscript.integration.tools.TestAssertion.any
import io.github.kscripting.kscript.integration.tools.TestAssertion.startsWith
import io.github.kscripting.kscript.integration.tools.TestAssertion.verify
import io.github.kscripting.kscript.integration.tools.TestContext.projectDir
import io.github.kscripting.kscript.integration.tools.TestContext.resolvePath
import io.github.kscripting.shell.integration.tools.TestContext.projectPath
import org.apache.commons.io.FileUtils
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
Expand All @@ -15,47 +11,67 @@ class AnnotationTest : TestBase {
@Tag("posix")
@Tag("windows")
fun `There are some dependencies which are not jar, but maybe pom, aar and others - make sure they work, too`() {
verify("kscript ${resolvePath("$projectDir/test/resources/depends_on_with_type.kts")}", 0, "getBigDecimal(1L): 1\n", any())
verify(
"kscript ${projectPath / "test/resources/depends_on_with_type.kts"}",
0,
"getBigDecimal(1L): 1[nl]",
any()
)
}

@Test
@Tag("posix")
@Tag("windows")
fun `Make sure that DependsOn is parsed correctly`() {
verify("kscript ${resolvePath("$projectDir/test/resources/depends_on_annot.kts")}", 0, "kscript with annotations rocks!\n", any())
verify(
"kscript ${projectPath / "test/resources/depends_on_annot.kts"}",
0,
"kscript with annotations rocks![nl]",
any()
)
}

@Test
@Tag("posix")
@Tag("windows")
fun `Make sure that DependsOnMaven is parsed correctly`() {
verify("kscript ${resolvePath("$projectDir/test/resources/depends_on_maven_annot.kts")}", 0, "kscript with annotations rocks!\n", any())
verify(
"kscript ${projectPath / "test/resources/depends_on_maven_annot.kts"}",
0,
"kscript with annotations rocks![nl]",
any()
)
}

@Test
@Tag("posix")
@Tag("windows")
fun `Make sure that dynamic versions are matched properly`() {
verify("kscript ${resolvePath("$projectDir/test/resources/depends_on_dynamic.kts")}", 0, "dynamic kscript rocks!\n", any())
verify(
"kscript ${projectPath / "test/resources/depends_on_dynamic.kts"}",
0,
"dynamic kscript rocks![nl]",
any()
)
}

@Test
@Tag("posix")
@Tag("windows")
fun `Make sure that MavenRepository is parsed correctly`() {
verify(
"kscript ${resolvePath("$projectDir/test/resources/custom_mvn_repo_annot.kts")}",
"kscript ${projectPath / "test/resources/custom_mvn_repo_annot.kts"}",
0,
"kscript with annotations rocks!\n",
startsWith("[kscript] Adding repository: Repository(id=, url=http://maven.imagej.net/content/repositories/releases, user=, password=)\n")
"kscript with annotations rocks![nl]",
startsWith("[kscript] Adding repository: Repository(id=, url=http://maven.imagej.net/content/repositories/releases, user=, password=)[nl]")
)
verify(
"kscript ${resolvePath("$projectDir/test/resources/illegal_depends_on_arg.kts")}",
"kscript ${projectPath / "test/resources/illegal_depends_on_arg.kts"}",
1,
"",
"[kscript] [ERROR] Artifact locators must be provided as separate annotation arguments and not as comma-separated list: [com.squareup.moshi:moshi:1.5.0,com.squareup.moshi:moshi-adapters:1.5.0]\n\n"
"[kscript] [ERROR] Artifact locators must be provided as separate annotation arguments and not as comma-separated list: [com.squareup.moshi:moshi:1.5.0,com.squareup.moshi:moshi-adapters:1.5.0][nl][nl]"
)
verify("kscript $projectDir/test/resources/script_with_compile_flags.kts", 0, "hoo_ray\n", any())
verify("kscript ${projectPath / "test/resources/script_with_compile_flags.kts"}", 0, "hoo_ray[nl]", any())
}

@Test
Expand All @@ -68,10 +84,10 @@ class AnnotationTest : TestBase {
}

verify(
"kscript ${resolvePath("$projectDir/test/resources/depends_on_klaxon.kts")}",
"kscript ${projectPath / "test/resources/depends_on_klaxon.kts"}",
0,
"Successfully resolved klaxon\n",
startsWith("[kscript] Resolving com.beust:klaxon:5.5...\n")
"Successfully resolved klaxon[nl]",
startsWith("[kscript] Resolving com.beust:klaxon:5.5...[nl]")
)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package io.github.kscripting.kscript.integration

import io.github.kscripting.kscript.integration.tools.TestAssertion.contains
import io.github.kscripting.kscript.integration.tools.TestAssertion.startsWith
import io.github.kscripting.kscript.integration.tools.TestAssertion.verify
import io.github.kscripting.kscript.integration.tools.TestContext.copyToTestPath
import io.github.kscripting.kscript.integration.tools.TestContext.resolvePath
import io.github.kscripting.kscript.integration.tools.TestContext.testDir
import io.github.kscripting.shell.integration.tools.TestContext
import io.github.kscripting.shell.integration.tools.TestContext.testPath
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test

Expand All @@ -16,25 +12,30 @@ class BootstrapHeaderTest : TestBase {
//TODO: Doesn't work on msys and cygwin for some reason
fun `Test adding bootstrap header`() {
// ensure script works as is
val testFile = resolvePath("$testDir/echo_stdin_args.kts")
verify("echo stdin | '$testFile' --foo bar", 0, "stdin | script --foo bar\n")
val testFile = testPath / "echo_stdin_args.kts"
verify("echo stdin | '$testFile' --foo bar", 0, "stdin | script --foo bar[nl]")

// add bootstrap header
verify("kscript --add-bootstrap-header '$testFile'", 0, "", contains("echo_stdin_args.kts updated"))

// ensure adding it again raises an error
verify("kscript --add-bootstrap-header '$testFile'", 1, "", startsWith("[kscript] [ERROR] Bootstrap header already detected:"))
verify(
"kscript --add-bootstrap-header '$testFile'",
1,
"",
startsWith("[kscript] [ERROR] Bootstrap header already detected:")
)

// ensure scripts works with header, including stdin
verify("echo stdin | '$testFile' --foo bar", 0, "stdin | script --foo bar\n")
verify("echo stdin | '$testFile' --foo bar", 0, "stdin | script --foo bar[nl]")

// ensure scripts works with header invoked with explicit `kscript`
verify("echo stdin | kscript '$testFile' --foo bar", 0, "stdin | script --foo bar\n")
verify("echo stdin | kscript '$testFile' --foo bar", 0, "stdin | script --foo bar[nl]")
}

companion object {
init {
copyToTestPath("test/resources/echo_stdin_args.kts")
TestContext.copyFile("test/resources/echo_stdin_args.kts", testPath)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.github.kscripting.kscript.integration

import io.github.kscripting.kscript.integration.tools.TestAssertion.startsWith
import io.github.kscripting.kscript.integration.tools.TestAssertion.verify
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
package io.github.kscripting.kscript.integration

import io.github.kscripting.kscript.integration.tools.TestContext.copyToExecutablePath
import io.github.kscripting.kscript.integration.tools.TestAssertion.any
import io.github.kscripting.kscript.integration.tools.TestAssertion.verify
import io.github.kscripting.kscript.integration.tools.TestContext.projectDir
import io.github.kscripting.shell.integration.tools.TestContext.copyFile
import io.github.kscripting.shell.integration.tools.TestContext.execPath
import io.github.kscripting.shell.integration.tools.TestContext.projectPath
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test

class CustomInterpretersTest : TestBase {
@Test
@Tag("posix")
fun `Execute mydsl as interpreter`() {
verify("mydsl \"println(foo)\"", 0, "bar\n", any())
verify("mydsl \"println(foo)\"", 0, "bar[nl]", any())
}

@Test
@Tag("posix")
fun `Execute mydsl test with deps`() {
verify("$projectDir/test/resources/custom_dsl/mydsl_test_with_deps.kts", 0, "foobar\n", any())
verify((projectPath / "test/resources/custom_dsl/mydsl_test_with_deps.kts").stringPath(), 0, "foobar[nl]", any())
}

companion object {
init {
copyToExecutablePath("test/resources/custom_dsl/mydsl")
copyFile("test/resources/custom_dsl/mydsl", execPath)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package io.github.kscripting.kscript.integration

import io.github.kscripting.kscript.integration.tools.TestAssertion.contains
import io.github.kscripting.kscript.integration.tools.TestAssertion.startsWith
import io.github.kscripting.kscript.integration.tools.TestAssertion.verify
import io.github.kscripting.kscript.integration.tools.TestContext.projectDir
import io.github.kscripting.kscript.integration.tools.TestContext.resolvePath
import io.github.kscripting.shell.integration.tools.TestContext.projectPath
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test

Expand All @@ -14,9 +10,9 @@ class DeprecatedReportTest : TestBase {
@Tag("windows")
fun `Make sure that for deprecated features warn is generated`() {
verify(
"kscript ${resolvePath("$projectDir/test/resources/deprecated_report.kt")}",
"kscript ${projectPath / "test/resources/deprecated_report.kt"}",
0,
"made it!\n",
"made it![nl]",
startsWith("[kscript] [WARN] There are deprecated features in scripts. Use --report option to print full report.")
)
}
Expand All @@ -26,7 +22,7 @@ class DeprecatedReportTest : TestBase {
@Tag("windows")
fun `Assert that report with deprecated features is generated`() {
verify(
"kscript --report ${resolvePath("$projectDir/test/resources/deprecated_report.kt")}",
"kscript --report ${projectPath / "test/resources/deprecated_report.kt"}",
0,
"",
contains("@file:DependsOn(\"org.apache.commons:commons-lang3:3.12.0\")")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.kscripting.kscript.integration

import io.github.kscripting.kscript.integration.tools.TestAssertion.verify
import io.github.kscripting.kscript.integration.tools.TestContext.projectDir
import io.github.kscripting.shell.integration.tools.TestContext.projectPath
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test

Expand All @@ -10,15 +9,15 @@ class EnvironmentTest : TestBase {
@Tag("posix")
@Tag("windows")
fun `Make sure that KOTLIN_HOME can be guessed from kotlinc correctly`() {
verify("kscript \"println(99)\"", 0, "99\n") { env -> env.remove("KOTLIN_HOME") }
verify("kscript \"println(99)\"", 0, "99[nl]") { env -> env.remove("KOTLIN_HOME") }
}

//TODO: test what happens if kotlin/kotlinc/java/gradle/idea is not in PATH

@Test
@Tag("posix")
fun `Run script that tries to find out its own filename via environment variable`() {
val path = "$projectDir/test/resources/uses_self_file_name.kts"
verify(path, 0, "Usage: uses_self_file_name.kts [-ae] [--foo] file+\n")
val path = (projectPath / "test/resources/uses_self_file_name.kts").toString()
verify(path, 0, "Usage: uses_self_file_name.kts [-ae] [--foo] file+[nl]")
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package io.github.kscripting.kscript.integration

import io.github.kscripting.kscript.integration.tools.TestAssertion.any
import io.github.kscripting.kscript.integration.tools.TestAssertion.verify
import io.github.kscripting.kscript.integration.tools.TestContext.copyToExecutablePath
import io.github.kscripting.kscript.integration.tools.TestContext.projectDir
import io.github.kscripting.kscript.integration.tools.TestContext.resolvePath
import io.github.kscripting.shell.integration.tools.TestContext.copyFile
import io.github.kscripting.shell.integration.tools.TestContext.execPath
import io.github.kscripting.shell.integration.tools.TestContext.projectPath
import io.github.kscripting.shell.util.Sanitizer
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test

Expand All @@ -14,7 +13,9 @@ class IdeaTest : TestBase {
@Tag("macos")
//TODO: On MSys and Cygwin test doesn't work, and is accomplished with timeout
fun `Temp projects with include symlinks`() {
val result = verify("kscript --idea ${resolvePath("$projectDir/test/resources/includes/include_variations.kts")}", 0, any(), any())
val result = verify(
"kscript --idea ${projectPath / "test/resources/includes/include_variations.kts"}", 0, any(), any(), outputSanitizer = Sanitizer.EMPTY_SANITIZER
)
val ideaDir = result.stderr.trim().lines().last().removePrefix("[kscript] ")
verify("cd $ideaDir && gradle build", 0, any(), any())
}
Expand All @@ -24,14 +25,15 @@ class IdeaTest : TestBase {
@Tag("macos")
//TODO: On MSys and Cygwin test doesn't work, and is accomplished with timeout
fun `Support diamond-shaped include schemes (see #133)`() {
val result = verify("kscript --idea ${resolvePath("$projectDir/test/resources/includes/diamond.kts")}", 0, any(), any())
val result =
verify("kscript --idea ${projectPath / "test/resources/includes/diamond.kts"}", 0, any(), any(), outputSanitizer = Sanitizer.EMPTY_SANITIZER)
val ideaDir = result.stderr.trim().lines().last().removePrefix("[kscript] ")
verify("cd $ideaDir && gradle build", 0, any(), any())
}

companion object {
init {
copyToExecutablePath("test/resources/idea")
copyFile("test/resources/idea", execPath)
}
}
}
Loading