/// <summary>
 /// Emmit the TestComplete event
 /// </summary>
 /// <param name="raw">result of test in text form</param>
 /// <param name="parsed">result of in type form</param>
 protected void RaiseComplete(string raw, TestResult parsed)
 {
     if (TestComplete != null)
     {
         TestComplete(this, new TestCompleteEventArgs(raw, parsed));
     }
 }
		private static void ParseFailure(string testCase, TestResult result)
		{
			if (result.Status == TestStatus.Failed)
			{
				string kExpectedStartDelimiter = "Expected: ";
				string kActualStartDelimiter = "But was:  ";
				int expectedStart = testCase.IndexOf(kExpectedStartDelimiter, testCase.IndexOf("<message"));
				if (expectedStart > 0)
				{
					int actualStart = testCase.IndexOf(kActualStartDelimiter, expectedStart);
					result.Failure.Expected = testCase.Substring(expectedStart + kExpectedStartDelimiter.Length, actualStart - expectedStart - kExpectedStartDelimiter.Length);

					int actualEnd = testCase.IndexOf('\"', actualStart + kActualStartDelimiter.Length + 1) + 1;
					if (actualEnd == 0)
					{
						actualEnd = testCase.IndexOf("]]", actualStart);
					}
					result.Failure.Actual = testCase.Substring(actualStart + kActualStartDelimiter.Length, actualEnd - actualStart - kActualStartDelimiter.Length);

					if (testCase.Contains("CDATA[  String"))
					{

						int differStart = testCase.LastIndexOf(' ', expectedStart) + 1;
						result.Failure.ActualDiffersAt = int.Parse(testCase.Substring(differStart, expectedStart - differStart - 1));
					}

					const string kLineStartDelimiter = ":line ";
					int lineStart = testCase.LastIndexOf(kLineStartDelimiter) + kLineStartDelimiter.Length;
					int lineEnd = testCase.IndexOf("]]", lineStart);
					int lineNumber = int.Parse(testCase.Substring(lineStart, lineEnd - lineStart));
					result.Failure.FailingStatement = DxCoreUtil.GetStatement(result.Location, lineNumber);
				}
			}
		}
		private static TestResult ParseCase(string testCase)
		{
			TestResult result = new TestResult();
			ParseCommonData(testCase, result);
			ParseFailure(testCase, result);
			return result;
		}
Beispiel #4
0
        public void NoExpectedValue_ReturnsEmptyString()
        {
            string        rawResult = "[failed] Test RedGreenPlayground/MbUnitTests/NotNull\nExpected value to be non-null.\n\nActual Value : null\n\n   at RedGreenPlayground.MbUnitTests.NotNull() in C:\\Users\\JAARGERO.WRPWI\\Documents\\Visual Studio 2005\\Projects\\RedGreenPlayground\\RedGreenPlayground\\MbUnitTests.cs:line 41\n\n\n";
            IResultParser parser    = new MbUnit3_1ResultParser();

            RedGreen.TestResult parsed = parser.ParseTest(rawResult);

            Assert.Equal(string.Empty, parsed.Failure.Expected);
        }
Beispiel #5
0
        public void MbUnitPassed()
        {
            string        rawResult = "[passed] Test RedGreenPlayground/MbUnitTests/AlwaysPass\n";
            IResultParser parser    = new MbUnit3_1ResultParser();

            RedGreen.TestResult parsed = parser.ParseTest(rawResult);

            Assert.Equal(RedGreen.TestStatus.Passed, parsed.Status);
            Assert.Equal("RedGreenPlayground.MbUnitTests.AlwaysPass", parsed.Location);
        }
Beispiel #6
0
        private void ValidateSkipped()
        {
            List <string> output = LoadOutput();

            List <RedGreen.TestResult> results = NUnitParser.ParseTestResults(output);

            RedGreen.TestResult alwaysFail = results.Find(r => r.Location == "RedGreenPlayground.NUnitTests.Skipped");

            Assert.Equal("RedGreenPlayground.NUnitTests.Skipped", alwaysFail.Location);
            Assert.Equal(RedGreen.TestStatus.Skipped, alwaysFail.Status);
        }
Beispiel #7
0
        private void ValidateIntFail()
        {
            List <string> output = LoadOutput();

            List <RedGreen.TestResult> results = NUnitParser.ParseTestResults(output);

            RedGreen.TestResult alwaysFail = results.Find(r => r.Location == "RedGreenPlayground.NUnitTests.IntFail");

            Assert.Equal("RedGreenPlayground.NUnitTests.IntFail", alwaysFail.Location);
            Assert.Equal(RedGreen.TestStatus.Failed, alwaysFail.Status);
            Assert.Equal("0", alwaysFail.Failure.Expected);
            Assert.Equal("1", alwaysFail.Failure.Actual);
            Assert.Equal(0, alwaysFail.Failure.ActualDiffersAt);
        }
Beispiel #8
0
        public void NUnitFaildInt()
        {
            string       rawResult = "[failed] Test NUnit v2.4.7.0/RedGreenPlayground/NUnitTests/IntFail\nMessage\n  Expected: 0\n  But was:  1\n\nStack Trace\n   at NUnit.Framework.Assert.That(Object actual, Constraint constraint, String message, Object[] args)\n   at NUnit.Framework.Assert.AreEqual(Int32 expected, Int32 actual, String message, Object[] args)\n   at NUnit.Framework.Assert.AreEqual(Int32 expected, Int32 actual)\n   at RedGreenPlayground.NUnitTests.IntFail() in C:\\Users\\jaargero.WRPWI\\Documents\\Visual Studio 2005\\Projects\\RedGreenPlayground\\RedGreenPlayground\\NUnitTests.cs:line 28\n\n";
            ResultParser parser    = new ResultParser();

            RedGreen.TestResult parsed = parser.ParseTest(rawResult);

            Assert.Equal(RedGreen.TestStatus.Failed, parsed.Status);
            Assert.Equal(string.Empty, parsed.Duration);
            Assert.Equal("0", parsed.Failure.Expected);
            Assert.Equal("1", parsed.Failure.Actual);
            Assert.Equal(0, parsed.Failure.ActualDiffersAt);
            Assert.Null(parsed.Failure.FailingStatement);
            Assert.Equal("RedGreenPlayground.NUnitTests.IntFail", parsed.Location);
        }
Beispiel #9
0
        private void ValidateAlwaysFail()
        {
            List <string> output = LoadOutput();

            List <RedGreen.TestResult> results = NUnitParser.ParseTestResults(output);

            RedGreen.TestResult alwaysFail = results.Find(r => r.Location == "RedGreenPlayground.NUnitTests.AlwaysFails");

            Assert.Equal("RedGreenPlayground.NUnitTests.AlwaysFails", alwaysFail.Location);
            Assert.Equal(RedGreen.TestStatus.Failed, alwaysFail.Status);
            Assert.Equal("0.019", alwaysFail.Duration);
            Assert.Equal("\"who's there\"", alwaysFail.Failure.Expected);
            Assert.Equal("\"who's where\"", alwaysFail.Failure.Actual);
            Assert.Equal(6, alwaysFail.Failure.ActualDiffersAt);
        }
Beispiel #10
0
        public void MbUnitFailedTestStringFail()
        {
            string       rawResult = "[failed] Test MbUnit v3.0.5.546/RedGreenPlayground/MbUnitTests/AlwaysFails\nExpected values to be equal.\n\nExpected Value : \"who\'s there\"\nActual Value   : \"who\'s where\"\n\n   at RedGreenPlayground.MbUnitTests.AlwaysFails() in C:\\Users\\jaargero.WRPWI\\Documents\\Visual Studio 2005\\Projects\\RedGreenPlayground\\RedGreenPlayground\\MbUnitTests.cs:line 21\n";
            ResultParser parser    = new ResultParser();

            RedGreen.TestResult parsed = parser.ParseTest(rawResult);

            Assert.Equal(RedGreen.TestStatus.Failed, parsed.Status);
            Assert.Equal(string.Empty, parsed.Duration);
            Assert.Equal("\"who\'s there\"", parsed.Failure.Expected);
            Assert.Equal("\"who\'s where\"", parsed.Failure.Actual);
            Assert.Equal(7, parsed.Failure.ActualDiffersAt);
            Assert.Null(parsed.Failure.FailingStatement);
            Assert.Equal("RedGreenPlayground.MbUnitTests.AlwaysFails", parsed.Location);
        }
Beispiel #11
0
        public void MbUnitFaildInt()
        {
            string        rawResult = "[failed] Test RedGreenPlayground/MbUnitTests/IntFail\nExpected values to be equal.\n\nExpected Value : 0\nActual Value   : 1\n\n   at RedGreenPlayground.MbUnitTests.IntFail() in C:\\Users\\JAARGERO.WRPWI\\Documents\\Visual Studio 2005\\Projects\\RedGreenPlayground\\RedGreenPlayground\\MbUnitTests.cs:line 28\n\n";
            IResultParser parser    = new MbUnit3_1ResultParser();

            RedGreen.TestResult parsed = parser.ParseTest(rawResult);

            Assert.Equal(RedGreen.TestStatus.Failed, parsed.Status);
            Assert.Equal(string.Empty, parsed.Duration);
            Assert.Equal("0", parsed.Failure.Expected);
            Assert.Equal("1", parsed.Failure.Actual);
            Assert.Equal(0, parsed.Failure.ActualDiffersAt);
            Assert.Null(parsed.Failure.FailingStatement);
            Assert.Equal("RedGreenPlayground.MbUnitTests.IntFail", parsed.Location);
        }
        public TestResult ParseTest(string rawResult)
        {
            int statusEnd = rawResult.IndexOf(' ');
            int kindEnd = rawResult.IndexOf(' ', statusEnd + 1);
            int engineEnd = rawResult.IndexOf(' ', kindEnd + 1);
            int versionEnd = rawResult.IndexOf('/', engineEnd + 1);
            int locationEnd = rawResult.IndexOf('\n', versionEnd + 1);
            string status = rawResult.Substring(1, statusEnd - 2);
            string kind = rawResult.Substring(statusEnd + 1, kindEnd - statusEnd - 1);
			string engine = rawResult.Substring(kindEnd + 1, engineEnd - kindEnd - 1);
            string location = rawResult.Substring(versionEnd + 1, locationEnd - versionEnd - 1);

            TestResult testResult = new TestResult();

            if (kind == ResultKind.Test)
            {
                IGallioResultParser helper = _parserFactory.GetParser(engine);

                testResult.Location = helper.ReformatLocation(location);

                switch (status.ToLower())
                {
                    case Status.Failed:
                    case Status.Error:
                        testResult.Status = TestStatus.Failed;
                        testResult.Duration = string.Empty;
                        string content = rawResult.Substring(locationEnd);
                        testResult.Failure.Expected = helper.GetExpected(content);
                        testResult.Failure.Actual = helper.GetActual(content);
                        testResult.Failure.FailingStatement = DxCoreUtil.GetStatement(testResult.Location, helper.GetLineNumber(content));
                        testResult.Failure.ActualDiffersAt = helper.GetPosition(content, testResult.Failure.Expected, testResult.Failure.Actual);
                        break;

                    case Status.Passed:
                        testResult.Status = TestStatus.Passed;
                        testResult.Duration = string.Empty;
                        break;

                    default:
                    case Status.Skipped:
                    case Status.Ignored:
                        testResult.Status = TestStatus.Skipped;
                        break;
                }
            }
            return testResult;
        }
		public TestResult ParseTest(string rawResult)
		{
			string header = rawResult.Substring(0, rawResult.IndexOf('\n'));
			string status = Regex.Match(header, @"\w+").Value;
			string kind = Regex.Match(header, @"\]\s\w+").Value.Substring(2);
			string location = header.Substring(header.LastIndexOf(' ') + 1);

			TestResult testResult = new TestResult();
			if (kind == ResultKind.Test)
			{
				//IGallioResultParser helper = _parserFactory.GetParser(engine);

				testResult.Location = location.Replace('/', '.');

				switch (status.ToLower())
				{
					case Status.Failed:
					case Status.Error:
						testResult.Status = TestStatus.Failed;
						testResult.Duration = string.Empty;
						string content = rawResult.Substring(rawResult.IndexOf('\n') + 1);
						testResult.Failure.Expected = GetExpected(content);
						testResult.Failure.Actual = GetActual(content);
						testResult.Failure.FailingStatement = DxCoreUtil.GetStatement(testResult.Location, GetLineNumber(content));
						testResult.Failure.ActualDiffersAt = GetPosition(content, testResult.Failure.Expected, testResult.Failure.Actual);
						break;

					case Status.Passed:
						testResult.Status = TestStatus.Passed;
						testResult.Duration = string.Empty;
						break;

					default:
					case Status.Skipped:
					case Status.Ignored:
						testResult.Status = TestStatus.Skipped;
						break;
				}
			}
			return testResult;
		}
 public TestCompleteEventArgs(string raw, TestResult result)
 {
     RawResult = raw;
     Result = result;
 }
        /// <summary>
        /// Draw the parsed error text at the end of the method causing the test failure 
        /// </summary>
        private void DrawError(EditorPaintLanguageElementEventArgs ea, TestResult testResult)
        {
            if (testResult.Status == TestStatus.Failed)
            {
                FailureData failure = testResult.Failure;
                if (failure.FailingStatement != null)
                {
                    int errorTextStartCol = failure.FailingStatement.EndOffset + 5;
                    if (string.IsNullOrEmpty(failure.Expected))
                    {// not an equal comparison
                        ea.PaintArgs.OverlayText("<------- Test failed here",
                            failure.FailingStatement.StartLine,
                            errorTextStartCol,
                            FailedColor);

                    }
                    else if (failure.ActualDiffersAt < 0)
                    {
                        ea.PaintArgs.OverlayText(string.Format("Expected: {0} Actual: {1}", failure.Expected, failure.Actual),
                            failure.FailingStatement.StartLine,
                            errorTextStartCol,
                            FailedColor);
                    }
                    else
                    {
                        int start = errorTextStartCol;
                        string correctPortion = string.Format("Expected: {0} Actual: {1}", failure.Expected, failure.Actual.Substring(0, failure.ActualDiffersAt));
                        ea.PaintArgs.OverlayText(correctPortion,
                            failure.FailingStatement.StartLine,
                            start,
                            FailedColor);
                        ea.PaintArgs.OverlayText(failure.Actual.Substring(failure.ActualDiffersAt),
                            failure.FailingStatement.StartLine,
                            start + correctPortion.Length,
                            Color.Red);
                    }
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the TestInfo class.
 /// </summary>
 private UnitTestDetail()
 {
     Result = new TestResult();
 }
		private static void ParseCommonData(string testCase, TestResult testResult)
		{
			string openTag = testCase.Substring(testCase.IndexOf('<'));
			string[] attributes = openTag.Split(' ');
			foreach (string keyValue in attributes)
			{
				if (keyValue.Contains("="))
                {
					int delimiter = keyValue.IndexOf("=");
					string key = keyValue.Substring(0, delimiter);
					string value = keyValue.Substring(delimiter + 2, keyValue.Length - delimiter - 3);
					switch (key)
					{
						case "name":
							testResult.Location = value;
							break;
						case "success":
							if (value == "False")
							{
								testResult.Status = TestStatus.Failed;
							}
							else if (value == "True")
							{
								testResult.Status = TestStatus.Passed;
							}
							else
							{
								testResult.Status = TestStatus.Unknown;
							}
							break;
						case "time":
							testResult.Duration = value;
							break;
						case "executed":
							testResult.Status = TestStatus.Skipped;
							break;
						default:
							break;
					}
				}
			}
		}