version test added; log error and result during version parsing updated

This commit is contained in:
Nadya Zabrodina
2013-07-25 18:33:35 +04:00
parent 6a8b530f5e
commit a6cff29057
2 changed files with 51 additions and 2 deletions
@@ -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);
}
}
@@ -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);
}
}