Example #1
0
    private void LogOverallResult(LinqTestBase test, int total, int failed, int asserted)
    {
      int passed = total - failed;
      int properlyFailed = failed - asserted;
      if (test is MaximumTest) {
        passed = total;
        properlyFailed = failed;
      }
      string score = string.Format("{0:F1}", passed * 100.0 / total);

      LogTotal(test.ShortToolName, "Total:", string.Empty, string.Empty);
      LogTotal(test.ShortToolName, Indent + "Performed", total, CountUnit);
      LogTotal(test.ShortToolName, Indent + "Passed",    passed, CountUnit);
      LogTotal(test.ShortToolName, Indent + "Failed",    failed, CountUnit);
      LogTotal(test.ShortToolName, Indent2 + "Properly", properlyFailed, CountUnit);
      LogTotal(test.ShortToolName, Indent2 + "Asserted", asserted, CountUnit);
      LogTotal(test.ShortToolName, Indent + "Score",  score, PercentageUnit);
    }
Example #2
0
    private void LogResult(LinqTestBase test, MethodInfo method, Exception error, bool isAssertion)
    {
      var testName = Indent + method.GetAttribute<CategoryAttribute>(AttributeSearchOptions.InheritNone).Name;
      var tool = test.ShortToolName;
      object result = scorecard.Get(tool, testName);
      var pair = new Pair<int, int>();
      if (result is Pair<int, int>)
        pair = (Pair<int, int>) result;
      pair = new Pair<int, int>(
        pair.First + (error!=null ? 1 : 0), 
        pair.Second + (isAssertion ? 1 : 0));
      scorecard.Set(tool, testName, pair);
      scorecard.Set(ToolTestBase.Unit, testName, BaseUnit);

      if (updateComments && !(test is MaximumTest)) {
        string comment = "Passed.";
        if (error!=null)
          comment = string.Format("Failed{0}.\r\nException: {1}\r\nMessage:\r\n{2}",
            isAssertion ? " with assertion" : string.Empty,
            error.GetType().GetShortName(),
            (error.Message ?? "none").Indent(2));
        var pattern = @"(?<Prefix>[\r\n]{2} (?<Indent>\s+)  \[Test\] \s*
		      [\r\n]{2} \k<Indent> \[Category\(.+\)\] *)
		      (?<Comment>
		      ([\r\n]{2} \s+ // \s+ .*)*
		      )
		      (?<Method>
		      [\r\n]{2} \s+ public \s+ void \s+ " + Regex.Escape(method.Name) + @" \s* \(\s*\) \s*
		      )";
        var regex = new Regex(pattern, RegexOptions.IgnorePatternWhitespace);
        var indent = regex.Matches(test.Source).Cast<Match>().Single().Groups["Indent"].Value;
        comment = comment.Split('\n')
          .Select(s => s.TrimEnd(' ', '\r'))
          .Reverse()
          .SkipWhile(s => s.Trim().Length==0)
          .Reverse()
          .Select(s => indent + @"// " + s)
          .ToDelimitedString("\r\n");
        test.Source = regex.Replace(test.Source, "${Prefix}\r\n" + comment + "${Method}");
      }
    }