Don't output error for "kotlinc -version"

#KT-9676 Fixed
This commit is contained in:
Alexander Udalov
2015-10-31 14:50:23 +03:00
parent 5335a81f7d
commit dce64c974f
8 changed files with 29 additions and 3 deletions
@@ -45,7 +45,6 @@ import org.jetbrains.kotlin.cli.jvm.config.JVMConfigurationKeys;
import org.jetbrains.kotlin.config.CompilerConfiguration;
import org.jetbrains.kotlin.config.ContentRootsKt;
import org.jetbrains.kotlin.config.Services;
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus;
import org.jetbrains.kotlin.js.analyze.TopDownAnalyzerFacadeForJS;
import org.jetbrains.kotlin.js.analyzer.JsAnalysisResult;
import org.jetbrains.kotlin.js.config.Config;
@@ -54,6 +53,7 @@ import org.jetbrains.kotlin.js.config.LibrarySourcesConfig;
import org.jetbrains.kotlin.js.facade.K2JSTranslator;
import org.jetbrains.kotlin.js.facade.MainCallParameters;
import org.jetbrains.kotlin.js.facade.TranslationResult;
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus;
import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.utils.PathUtil;
@@ -88,8 +88,11 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
final MessageSeverityCollector messageSeverityCollector = new MessageSeverityCollector(messageCollector);
if (arguments.freeArgs.isEmpty()) {
if (arguments.version) {
return OK;
}
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, "Specify at least one source file or directory", NO_LOCATION);
return ExitCode.COMPILATION_ERROR;
return COMPILATION_ERROR;
}
CompilerConfiguration configuration = new CompilerConfiguration();
@@ -185,6 +185,9 @@ public open class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) return COMPILATION_ERROR
if (environment.getSourceFiles().isEmpty()) {
if (arguments.version) {
return OK
}
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, "No source files", CompilerMessageLocation.NO_LOCATION)
return COMPILATION_ERROR
}
+1
View File
@@ -0,0 +1 @@
-version
+2
View File
@@ -0,0 +1,2 @@
info: Kotlin Compiler version $VERSION$
OK
+1
View File
@@ -0,0 +1 @@
-version
+2
View File
@@ -0,0 +1,2 @@
info: Kotlin Compiler version $VERSION$
OK
@@ -26,6 +26,7 @@ import kotlin.io.FilesKt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.cli.common.CLICompiler;
import org.jetbrains.kotlin.cli.common.ExitCode;
import org.jetbrains.kotlin.cli.common.KotlinVersion;
import org.jetbrains.kotlin.cli.js.K2JSCompiler;
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
import org.jetbrains.kotlin.load.java.JvmAbi;
@@ -72,7 +73,8 @@ public class CliBaseTest {
String normalizedOutputWithoutExitCode = pureOutput
.replace(new File(testDataDir).getAbsolutePath(), "$TESTDATA_DIR$")
.replace("expected ABI version is " + JvmAbi.VERSION, "expected ABI version is $ABI_VERSION$")
.replace("\\", "/");
.replace("\\", "/")
.replace(KotlinVersion.VERSION, "$VERSION$");
return removePerfOutput(normalizedOutputWithoutExitCode) + exitCode;
}
@@ -223,6 +223,12 @@ public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTes
doJvmTest(fileName);
}
@TestMetadata("version.args")
public void testVersion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/version.args");
doJvmTest(fileName);
}
@TestMetadata("warningsInDummy.args")
public void testWarningsInDummy() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/warningsInDummy.args");
@@ -364,6 +370,12 @@ public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTes
doJsTest(fileName);
}
@TestMetadata("version.args")
public void testVersion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js/version.args");
doJsTest(fileName);
}
@TestMetadata("withFolderAsLib.args")
public void testWithFolderAsLib() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js/withFolderAsLib.args");