public AssertFailException(InterpBase value, InterpValue left, InterpValue right) : base("Assertion failed for: " + value + Environment.NewLine + "Left: " + left + Environment.NewLine + "Right: " + right) { IsDetailed = true; Value = value; Left = left; Right = right; }
static bool Run(string name, InterpBase func, InterpEnvironment env, DisplayMode display = DisplayMode.All) { try { func.Interp(env); if (display.HasFlag(DisplayMode.Success)) { Console.WriteLine(name); WriteColour("\t[Passed]", GoodColour); } return(true); } catch (AssertFailException afe) { if (display.HasFlag(DisplayMode.Errors)) { Console.WriteLine(name); WriteColour("\t[Failed]: " + afe.Message, FailColour); } } catch (WrongTypeException wte) { if (display.HasFlag(DisplayMode.Errors)) { Console.WriteLine(name); WriteColour("\t[Failed]: " + wte.Message, IndeterminateColour); } } catch (UndefinedIdentifierException uie) { if (display.HasFlag(DisplayMode.Errors)) { Console.WriteLine(name); WriteColour("\t[Failed]: " + uie.Message, IndeterminateColour); } } catch (Exception ex) { if (display.HasFlag(DisplayMode.Errors)) { Console.WriteLine(name); WriteColour("\t[Failed]: " + ex.Message, IndeterminateColour); } } return(false); }
public AssertFailException(InterpBase value) : base("Assertion failed for: " + value) { Value = value; IsDetailed = false; }
static void Run(IDictionary <string, InterpBase> functions, InterpEnvironment baseEnv) { if (functions.ContainsKey(PrerunFunction)) { Run(PrerunFunction, functions[PrerunFunction], baseEnv, DisplayMode.Errors | DisplayMode.Exceptions); } InterpBase beforeFunc = null, afterFunc = null; if (functions.ContainsKey(BeforeFunction)) { beforeFunc = functions[BeforeFunction]; } if (functions.ContainsKey(AfterFunction)) { afterFunc = functions[AfterFunction]; } int passed = 0, total = 0; foreach (var function in functions) { if (ShouldRun(function.Key)) { var env = baseEnv.Clone(); if (beforeFunc != null) { Run(BeforeFunction, beforeFunc, env, DisplayMode.Errors | DisplayMode.Exceptions); } if (Run(function.Key, function.Value, env)) { passed++; } if (afterFunc != null) { Run(AfterFunction, afterFunc, env, DisplayMode.Errors | DisplayMode.Exceptions); } total++; } } if (functions.ContainsKey(PostrunFunction)) { Run(PostrunFunction, functions[PostrunFunction], baseEnv, DisplayMode.Errors | DisplayMode.Exceptions); } if (total != 0) { var temp = Console.ForegroundColor; if (passed == total) { Console.ForegroundColor = GoodColour; } else if (passed / (double)total > 0.75) { Console.ForegroundColor = IndeterminateColour; } else { Console.ForegroundColor = FailColour; } Console.WriteLine(); Console.WriteLine($"\t{passed} / {total} ({passed / (double)total * 100}%) tests passed"); Console.ForegroundColor = temp; } }