private void RunCodeToolStripMenuItem_Click(object sender, EventArgs e) { canvasForm?.ClearEvents(); jsRunner.Reset(); var errs = jsRunner.Run(); errorListForm?.SetRuntimeErrors(errs); if (errs.Length == 0) { canvasForm?.RefreshEvents(); } }
public void TestMethod1() { var jsCode = @" return data.value + 2 + myData; "; using (var runner = new JsRunner()) { //添加依赖的js文件 runner.AddJsFile("/UnitTestProject1/JavaScript1.js"); var value = runner.Run <int>(jsCode, new { value = 3 }); if (value != 15) { throw new Exception("结果错误"); } } }
private static void Execute(TestCase test, TestDriverSettings settings) { if (test.IsBenchmark) { if (settings.IsSWF) { var results = FlashPlayer.Run(test.OutputPath); test.Output2 = results.Output; return; } throw new NotImplementedException(); } int exitCode1 = 0; if (!test.HasOutput) { test.VM = VM.CLR; test.Output1 = CommandPromt.Run(test.ExePath, "", out exitCode1); } else { test.Output1 = test.Output; } int exitCode2; if (settings.IsClrEmulation) { try { var console = new StringWriter(); var vm = new VirtualMachine(console); exitCode2 = vm.Run(test.ExePath, "", new string[0]); test.Output2 = console.ToString(); } catch (Exception e) { exitCode2 = 0; test.Output2 = e.ToString(); } } else if (settings.IsJavaScript) { try { test.Output2 = JsRunner.Run(test.OutputPath, null, out exitCode2); } catch (Exception e) { exitCode2 = 0; test.Output2 = e.ToString(); } } else if (settings.IsABC) { var avmOpts = new AvmShell.Options(); test.Output2 = AvmShell.Run(avmOpts, out exitCode2, test.OutputPath); } else if (settings.IsSWF) { //tc.Output2 = FlashShell.Run(outpath, out exitCode2); FlashPlayer.Path = @"c:\pfx\tools\fp10.exe"; var results = FlashPlayer.Run(test.OutputPath); exitCode2 = results.ExitCode; test.Output2 = results.Output; } else { throw new NotImplementedException(); } CreateDebugHooks(test, settings, test.OutputPath); if (test.CheckExitCode) { if (exitCode2 != 0) { test.Error = string.Format("{0} returned non zero exit code {1}.", test.OutputPath, exitCode2); return; } if (exitCode1 != 0) { test.Error = string.Format("{0} returned non zero exit code {1}.", test.ExePath, exitCode1); return; } } if (test.CompareOutputs) { test.Error = CompareTools.CompareLines(test.Output1, test.Output2, true); } }