/* * Copyright 2000-2009 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 jetbrains.teamcity.core.test; import java.util.regex.Matcher; import java.util.regex.Pattern; import jetbrains.teamcity.core.Debug; class CUnitParser implements ITraceElementParser { private static final Pattern C_TRACE_ELEMENT_PATTERN_0 = Pattern.compile(".*failed at (.*\\..*):\\d*\\((.*\\..*):(\\d*)\\).*"); private static final Pattern C_TRACE_ELEMENT_PATTERN_1 = Pattern.compile(".*: (.*::.*) *line: *(\\d*) (.*\\..*).*"); private static final Pattern C_TRACE_ELEMENT_PATTERN_2 = Pattern.compile("(.*\\..*)\\((\\d*)\\).*"); public IStackTraceElement parse(final String line){ try{ Matcher matcher = C_TRACE_ELEMENT_PATTERN_0.matcher(line); if(matcher.matches()){ return new StackTraceElement(IStackTraceElement.Type.CUNIT, line, null, normilizePath(matcher.group(2)), new Integer(matcher.group(3))); } matcher = C_TRACE_ELEMENT_PATTERN_1.matcher(line); if(matcher.matches()){ return new StackTraceElement(IStackTraceElement.Type.CUNIT, line, null, normilizePath(matcher.group(3)), new Integer(matcher.group(2))); } matcher = C_TRACE_ELEMENT_PATTERN_2.matcher(line); if(matcher.matches()){ return new StackTraceElement(IStackTraceElement.Type.CUNIT, line, null, normilizePath(matcher.group(1)), new Integer(matcher.group(2))); } } catch (Throwable e){ Debug.getInstance().log(Debug.DEBUG_PARSER, e); } return null; } private String normilizePath(final String path) { //process the case: //test: S1CUTest::test1 (F) line: 21 /[..]/cppunit/s1_CUtest.cpp return path.replace("[..]", ".."); } public static void main(String[] args){ final CUnitParser unitParser = new CUnitParser(); unitParser.parse("Assertion '0==1' failed at ../../folder/Dir/fileName.c:17(../../folder/Dir/fileName.c:17)"); unitParser.parse("test: OsTimerTest::testOneShotAt (F) line: 269 os/OsTimerTest.cpp"); unitParser.parse("c:\\novounittest\\triangledemo\\testtriangle\\testtriangle.cpp(30):Assertion"); } }