Example #1
0
 protected override String PreprocessResult(String s_actual)
 {
     if (s_actual == null) return null;
     return s_actual.SplitLines().Select(ln =>
     {
         if (ln.Trim().IsEmpty()) return ln;
         var indent = Seq.Nats.First(i => ln[i] != ' ');
         var s_indent = ln.Slice(0, indent);
         ln = ln.Slice(indent);
         while (ln.Contains("  ")) ln = ln.Replace("  ", " ");
         return s_indent + ln;
     }).StringJoin(Environment.NewLine);
 }
Example #2
0
        private void Verify(String s_actual, String fileName, String what, Type t_kernel)
        {
            var success = false;
            String failMsg = null;
            if (fileName != null)
            {
                var asm = MethodInfo.GetCurrentMethod().DeclaringType.Assembly;
                var s_reference = asm.ReadText(fileName);

                if (s_reference.IsEmpty())
                {
                    Log.WriteLine(s_actual);

                    Assert.Fail(String.Format(
                        "Reference " + what + " for the kernel '{1}' is empty.{0}" +
                        "Please, verify the trace dumped above and put in into the resource file.",
                        Environment.NewLine, t_kernel.GetCSharpRef(ToCSharpOptions.Informative)));
                }
                else
                {
                    var expected = s_reference.SplitLines();
                    var actual = s_actual.SplitLines();
                    if (expected.Count() != actual.Count())
                    {
                        failMsg = String.Format(
                            "Number of lines doesn't match. Expected {0}, actually found {1}" + Environment.NewLine,
                            expected.Count(), actual.Count());
                    }
                    else
                    {
                        success = expected.Zip(actual).SkipWhile((t, i) =>
                        {
                            if (t.Item1 != t.Item2)
                            {
                                var maxLines = Math.Max(actual.Count(), expected.Count());
                                var maxDigits = (int)Math.Floor(Math.Log10(maxLines)) + 1;
                                failMsg = String.Format(
                                    "Line {1} (starting from 1) doesn't match.{0}{4}{2}{0}{5}{3}{0}",
                                    Environment.NewLine, i + 1,
                                    t.Item1.Replace(" ", "·"), t.Item2.Replace(" ", "·"),
                                    "E:".PadRight(maxDigits + 3), "A:".PadRight(maxDigits + 3));
                                return false;
                            }
                            else
                            {
                                return true;
                            }
                        }).IsEmpty();
                    }

                    if (!success)
                    {
                        Log.WriteLine(t_kernel.GetCSharpRef(ToCSharpOptions.Informative));
                        Log.WriteLine(String.Empty);

                        var maxLines = Math.Max(actual.Count(), expected.Count());
                        var maxDigits = (int)Math.Floor(Math.Log10(maxLines)) + 1;
                        var maxActual = Math.Max(actual.MaxOrDefault(line => line.Length), "Actual".Length);
                        var maxExpected = Math.Max(expected.MaxOrDefault(line => line.Length), "Expected".Length);
                        var total = maxDigits + 3 + maxActual + 3 + maxExpected;

                        Log.WriteLine(String.Format("{0} | {1} | {2}",
                            "N".PadRight(maxDigits),
                            "Actual".PadRight(maxActual),
                            "Expected".PadRight(maxExpected)));
                        Log.WriteLine(total.Times("-"));

                        0.UpTo(maxLines - 1).ForEach(i =>
                        {
                            var l_actual = actual.ElementAtOrDefault(i, String.Empty);
                            var l_expected = expected.ElementAtOrDefault(i, String.Empty);
                            Log.WriteLine(String.Format("{0} | {1} | {2}",
                                i.ToString().PadLeft(maxDigits),
                                l_actual.PadRight(maxActual),
                                l_expected.PadRight(maxExpected)));
                        });

                        Log.WriteLine(String.Empty);
                        Log.WriteLine(failMsg);
                        Log.WriteLine(String.Empty);
                        Assert.Fail(what.Capitalize() + " doesn't match reference " + what + ".");
                    }
                }
            }
            else
            {
                Log.WriteLine(s_actual);

                Assert.Fail(String.Format(
                    "Couldn't find a file in resource that contains reference " + what + " for the kernel '{1}'.{0}" +
                    "Please, verify the trace dumped above and put in into the '{2}' file under the Reference folder next to tests.{0}" +
                    "Also be sure not to forget to select build action 'Embedded Resource' in file properties widget.",
                    Environment.NewLine, t_kernel.GetCSharpRef(ToCSharpOptions.Informative), fileName));
            }
        }
Example #3
0
        protected void VerifyResult(String s_expected, String s_actual)
        {
            (s_expected != null && s_actual != null).AssertTrue();
            s_expected = PreprocessReference(s_expected);
            s_actual = PreprocessResult(s_actual);

            var success = false;
            String failMsg = null;
            if (s_expected.IsEmpty())
            {
                Log.EnsureBlankLine();
                Log.WriteLine(s_actual);

                Assert.Fail(String.Format(
                    "Reference result for unit test '{1}' is empty.{0}" +
                    "Please, verify the trace dumped above and put in into the resource file.",
                    Environment.NewLine, UnitTest.CurrentTest.GetCSharpRef(ToCSharpOptions.Informative)));
            }
            else
            {
                var expected = s_expected.SplitLines();
                var actual = s_actual.SplitLines();
                if (expected.Count() != actual.Count())
                {
                    success = false;
                    failMsg = String.Format(
                        "Number of lines doesn't match. Expected {0}, actually found {1}" + Environment.NewLine,
                        expected.Count(), actual.Count());
                }
                else
                {
                    success = expected.Zip(actual).SkipWhile((t, i) =>
                    {
                        if (t.Item1 != t.Item2)
                        {
                            var maxLines = Math.Max(actual.Count(), expected.Count());
                            var maxDigits = (int)Math.Floor(Math.Log10(maxLines)) + 1;
                            failMsg = String.Format(
                                "Line {1} (starting from 1) doesn't match.{0}{4}{2}{0}{5}{3}",
                                Environment.NewLine, i + 1,
                                t.Item1.Replace(" ", "·"), t.Item2.Replace(" ", "·"),
                                "E:".PadRight(maxDigits + 3), "A:".PadRight(maxDigits + 3));
                            return false;
                        }
                        else
                        {
                            return true;
                        }
                    }).IsEmpty();
                }

                if (!success)
                {
                    var maxLines = Math.Max(actual.Count(), expected.Count());
                    var maxDigits = (int)Math.Floor(Math.Log10(maxLines + 1)) + 1;
                    var maxActual = Math.Max(actual.MaxOrDefault(line => line.Length), "Actual".Length);
                    var maxExpected = Math.Max(expected.MaxOrDefault(line => line.Length), "Expected".Length);
                    var total = maxDigits + 3 + maxActual + 3 + maxExpected;

                    Log.EnsureBlankLine();
                    Log.WriteLine(String.Format("{0} | {1} | {2}",
                        "N".PadRight(maxDigits),
                        "Actual".PadRight(maxActual),
                        "Expected".PadRight(maxExpected)));
                    Log.WriteLine(total.Times("-"));

                    0.UpTo(maxLines - 1).ForEach(i =>
                    {
                        var l_actual = actual.ElementAtOrDefault(i, String.Empty);
                        var l_expected = expected.ElementAtOrDefault(i, String.Empty);
                        Log.WriteLine(String.Format("{0} | {1} | {2}",
                            (i + 1).ToString().PadLeft(maxDigits),
                            l_actual.PadRight(maxActual),
                            l_expected.PadRight(maxExpected)));
                    });

                    Log.EnsureBlankLine();
                    Log.WriteLine(failMsg);
                    Assert.Fail("Actual result doesn't match expected result.");
                }
            }
        }