Implement -no-stdlib argument support in kotlin runner

#KT-43294 fixed
This commit is contained in:
Ilya Chernikov
2021-01-04 16:01:53 +01:00
parent d2ecc1e361
commit edc730f70b
2 changed files with 17 additions and 1 deletions
@@ -44,6 +44,7 @@ object Main {
val arguments = arrayListOf<String>() val arguments = arrayListOf<String>()
val compilerArguments = arrayListOf<String>() val compilerArguments = arrayListOf<String>()
var expression: String? = null var expression: String? = null
var noStdLib = false
var noReflect = false var noReflect = false
fun setExpression(expr: String) { fun setExpression(expr: String) {
@@ -102,6 +103,10 @@ object Main {
collectingExpressions = true collectingExpressions = true
needsCompiler = true needsCompiler = true
} }
else if ("-no-stdlib" == arg) {
noStdLib = true
compilerArguments.add(arg)
}
else if ("-no-reflect" == arg) { else if ("-no-reflect" == arg) {
noReflect = true noReflect = true
compilerArguments.add(arg) compilerArguments.add(arg)
@@ -132,7 +137,9 @@ object Main {
classpath.addPath(".") classpath.addPath(".")
} }
classpath.addPath("$KOTLIN_HOME/lib/kotlin-stdlib.jar") if (!noStdLib) {
classpath.addPath("$KOTLIN_HOME/lib/kotlin-stdlib.jar")
}
if (!noReflect) { if (!noReflect) {
classpath.addPath("$KOTLIN_HOME/lib/kotlin-reflect.jar") classpath.addPath("$KOTLIN_HOME/lib/kotlin-reflect.jar")
@@ -185,6 +192,7 @@ and possible options include:
-classpath (-cp) <path> Paths where to find user class files -classpath (-cp) <path> Paths where to find user class files
-Dname=value Set a system JVM property -Dname=value Set a system JVM property
-J<option> Pass an option directly to JVM -J<option> Pass an option directly to JVM
-no-stdlib Don't include Kotlin standard library into classpath
-no-reflect Don't include Kotlin reflection implementation into classpath -no-reflect Don't include Kotlin reflection implementation into classpath
-X<flag>[=value] Pass -X argument to the compiler -X<flag>[=value] Pass -X argument to the compiler
-version Display Kotlin version -version Display Kotlin version
@@ -248,6 +248,14 @@ fun f() : Result<Int> = Result.success(42)
runProcess("kotlin", "-Xallow-result-return-type", "$testDataDirectory/funWithResultReturn.kts", expectedStdout = "42\n") runProcess("kotlin", "-Xallow-result-return-type", "$testDataDirectory/funWithResultReturn.kts", expectedStdout = "42\n")
} }
fun testNoStdLib() {
runProcess("kotlin", "-e", "println(42)", expectedStdout = "42\n")
runProcess(
"kotlin", "-no-stdlib", "-e", "println(42)",
expectedExitCode = 1, expectedStderrContains = Regex("error: unresolved reference: println")
)
}
fun testProperty() { fun testProperty() {
runProcess("kotlinc", "$testDataDirectory/property.kt", "-d", tmpdir.path) runProcess("kotlinc", "$testDataDirectory/property.kt", "-d", tmpdir.path)