TestBase.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. using Jint.Runtime;
  5. using Xunit;
  6. using Xunit.Extensions;
  7. namespace Jint.Tests
  8. {
  9. public class TestBase
  10. {
  11. private string _basePath;
  12. public TestBase(params string[] segments)
  13. {
  14. _basePath = @"C:\Users\sebros\Documents\My Projects\Jint\Jint.Tests\Scripts\Test262\suite\";
  15. _basePath = Path.Combine(_basePath, Path.Combine(segments));
  16. }
  17. public void Run(string filename)
  18. {
  19. var assembly = Assembly.GetExecutingAssembly();
  20. var scriptPath = Path.Combine(_basePath, filename);
  21. string fileContent = File.ReadAllText(scriptPath);
  22. RunTest(fileContent);
  23. }
  24. private Action<string> ERROR = s => { throw new Exception(s); };
  25. public void RunTest(string source)
  26. {
  27. var engine = new Engine(cfg => cfg
  28. .WithDelegate("$ERROR", ERROR)
  29. );
  30. engine.Execute(source);
  31. }
  32. }
  33. }