From a6cff29057ae2e9400f9843e47c809c5fdef6e6f Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Thu, 25 Jul 2013 18:30:13 +0400 Subject: [PATCH] version test added; log error and result during version parsing updated --- .../hg4idea/command/HgVersionCommand.java | 9 +++- .../hg4idea/test/version/HgVersionTest.java | 44 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 plugins/hg4idea/testSrc/hg4idea/test/version/HgVersionTest.java diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgVersionCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgVersionCommand.java index 04e2e9d145c8..aaaa9a9458b6 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgVersionCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgVersionCommand.java @@ -27,7 +27,8 @@ import java.util.regex.Pattern; public class HgVersionCommand { private static final Logger LOGGER = Logger.getInstance(HgVersionCommand.class); - private static final Pattern HG_VERSION_PATTERN = Pattern.compile(".+\\(\\s*version\\s+([0-9]+\\.[0-9]*)\\+?([0-9]*)[0-9\\.]*\\s*\\)\\s*"); + private static final Pattern HG_VERSION_PATTERN = + Pattern.compile(".+\\(\\s*version\\s+([0-9]+\\.[0-9]*)\\+?([0-9]*)[0-9\\.]*\\s*\\)\\s*"); public Double getVersion(String executable, boolean isRunViaBash) { String hgExecutable = executable == null ? null : executable.trim(); @@ -56,6 +57,10 @@ public class HgVersionCommand { if (matcher.matches()) { return Double.valueOf(matcher.group(1).concat(matcher.group(2))); } - return null; + if (versionResult.getOutputLines().isEmpty()) { + return null; + } + LOGGER.error("Couldn't identify hg version: " + versionResult.getOutputLines()); + return new Double(0); } } diff --git a/plugins/hg4idea/testSrc/hg4idea/test/version/HgVersionTest.java b/plugins/hg4idea/testSrc/hg4idea/test/version/HgVersionTest.java new file mode 100644 index 000000000000..ecc29135d7c7 --- /dev/null +++ b/plugins/hg4idea/testSrc/hg4idea/test/version/HgVersionTest.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package hg4idea.test.version; + +import hg4idea.test.HgPlatformTest; +import org.jetbrains.annotations.NotNull; +import org.zmlx.hg4idea.HgVcs; +import org.zmlx.hg4idea.command.HgVersionCommand; + +/** + * @author Nadya Zabrodina + */ +public class HgVersionTest extends HgPlatformTest { + + @NotNull private HgVcs myVcs; + + @Override + protected void setUp() throws Exception { + super.setUp(); + HgVcs vcs = HgVcs.getInstance(myProject); + assertNotNull(vcs); + myVcs = vcs; + } + + public void testVersionCommandForCurrentHgVersion() { + Double version = + new HgVersionCommand().getVersion(myVcs.getGlobalSettings().getHgExecutable(), myVcs.getGlobalSettings().isRunViaBash()); + assertNotNull(version); + assertTrue(version > 0); + } +}