Program.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Disable warning 429 (Unreachable code) because of the RESTRICT_TEST condition below.
  2. #pragma warning disable 429
  3. using System;
  4. using System.Collections.Generic;
  5. using MoonSharp.Interpreter.Diagnostics;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Text;
  9. using MoonSharp.Interpreter.Tests;
  10. using NUnit.Framework;
  11. using System.Diagnostics;
  12. namespace MoonSharpTests
  13. {
  14. class Program
  15. {
  16. public const string RESTRICT_TEST = null;//"LoopWithReturn";
  17. static void Main(string[] args)
  18. {
  19. int ok = 0;
  20. int fail = 0;
  21. int total = 0;
  22. Console.WriteLine("Moon# Test Suite Runner");
  23. Console.WriteLine("Copyright (C) 2014 Marco Mastropaolo [http://www.mastropaolo.com]");
  24. Console.WriteLine("See : http://moonsharp.codeplex.com");
  25. Console.WriteLine();
  26. Assembly asm = Assembly.GetAssembly(typeof(SimpleTests));
  27. foreach (Type t in asm.GetTypes().Where(t => t.GetCustomAttributes(typeof(TestFixtureAttribute), true).Any()))
  28. {
  29. foreach (MethodInfo mi in t.GetMethods().Where(m => m.GetCustomAttributes(typeof(TestAttribute), true).Any()))
  30. {
  31. if (RESTRICT_TEST != null && mi.Name != RESTRICT_TEST)
  32. continue;
  33. if (RunTest(t, mi))
  34. ++ok;
  35. else
  36. ++fail;
  37. ++total;
  38. }
  39. }
  40. Console.WriteLine("");
  41. Console.WriteLine("OK : {0}/{2}, Failed {1}/{2}", ok, fail, total);
  42. if (Debugger.IsAttached)
  43. {
  44. Console.WriteLine("Press any key...");
  45. Console.ReadKey();
  46. }
  47. }
  48. private static bool RunTest(Type t, MethodInfo mi)
  49. {
  50. Console.Write("{0}...", mi.Name);
  51. try
  52. {
  53. object o = Activator.CreateInstance(t);
  54. mi.Invoke(o, new object[0]);
  55. Console.WriteLine(" ok ");
  56. return true;
  57. }
  58. catch (Exception ex)
  59. {
  60. Console.WriteLine(" failed - {0}", ex.InnerException.Message);
  61. return false;
  62. }
  63. }
  64. }
  65. }