protected IEnumerable<Metacomment> RunSingleComparisonTestCase ( object[] parameters, Func<Configuration> makeConfiguration = null, JSEvaluationConfig evaluationConfig = null, Action<Exception> onTranslationFailure = null, string compilerOptions = "", Action<AssemblyTranslator> initializeTranslator = null, Func<string> getTestRunnerQueryString = null, bool? scanForProxies = null, string[] extraDependencies = null, bool shouldRunJs = true, string testFolderNameOverride = null ) { if (parameters.Length != 5) throw new ArgumentException("Wrong number of test case data parameters."); var provider = (TypeInfoProvider)parameters[1]; var cache = (AssemblyCache)parameters[2]; try { return RunComparisonTest( (string)parameters[0], null, provider, null, null, (string)parameters[3], shouldRunJs, cache, makeConfiguration: makeConfiguration, evaluationConfig: evaluationConfig, onTranslationFailure: onTranslationFailure, compilerOptions: compilerOptions, initializeTranslator: initializeTranslator, getTestRunnerQueryString: getTestRunnerQueryString, scanForProxies: scanForProxies, extraDependencies: extraDependencies, testFolderNameOverride: testFolderNameOverride ); } finally { if ((bool)parameters[4]) { if (provider != null) provider.Dispose(); if (cache != null) cache.Dispose(); } } }
private CompileResult RunComparisonTest ( string filename, string[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null, Action<string, string> errorCheckPredicate = null, List<string> failureList = null, string commonFile = null, bool shouldRunJs = true, AssemblyCache asmCache = null, Func<Configuration> makeConfiguration = null, Action<Exception> onTranslationFailure = null, JSEvaluationConfig evaluationConfig = null, string compilerOptions = "", Action<AssemblyTranslator> initializeTranslator = null, Func<string> getTestRunnerQueryString = null, bool? scanForProxies = null ) { CompileResult result = null; Console.WriteLine("// {0} ... ", Path.GetFileName(filename)); filename = Portability.NormalizeDirectorySeparators(filename); try { var testFilenames = new List<string>() { filename }; if (commonFile != null) testFilenames.Add(commonFile); using (var test = new ComparisonTest( EvaluatorPool, testFilenames, Path.Combine( ComparisonTest.TestSourceFolder, ComparisonTest.MapSourceFileToTestFile(filename) ), stubbedAssemblies, typeInfo, asmCache, compilerOptions: compilerOptions )) { test.GetTestRunnerQueryString = getTestRunnerQueryString ?? test.GetTestRunnerQueryString; result = test.CompileResult; if (shouldRunJs) { test.Run( makeConfiguration: makeConfiguration, evaluationConfig: evaluationConfig, onTranslationFailure: onTranslationFailure, initializeTranslator: initializeTranslator, scanForProxies: scanForProxies ); } else { string js; long elapsed; try { var csOutput = test.RunCSharp(new string[0], out elapsed); test.GenerateJavascript( new string[0], out js, out elapsed, makeConfiguration, evaluationConfig == null || evaluationConfig.ThrowOnUnimplementedExternals, onTranslationFailure, initializeTranslator ); Console.WriteLine("generated"); if (errorCheckPredicate != null) { errorCheckPredicate(csOutput, js); } } catch (Exception) { Console.WriteLine("error"); throw; } } } } catch (Exception ex) { if (ex.Message == "JS test failed") Debug.WriteLine(ex.InnerException); else Debug.WriteLine(ex); if (failureList != null) { failureList.Add(Path.GetFileNameWithoutExtension(filename)); } else throw; } return result; }
private IEnumerable<Metacomment> RunComparisonTest ( string filename, string[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null, Action<string, Func<string>> errorCheckPredicate = null, List<string> failureList = null, string commonFile = null, bool shouldRunJs = true, AssemblyCache asmCache = null, Func<Configuration> makeConfiguration = null, Action<Exception> onTranslationFailure = null, JSEvaluationConfig evaluationConfig = null, string compilerOptions = "", Action<AssemblyTranslator> initializeTranslator = null, Func<string> getTestRunnerQueryString = null, bool? scanForProxies = null, string[] extraDependencies = null, string testFolderNameOverride = null ) { IEnumerable<Metacomment> result = null; Console.WriteLine("// {0} ... ", Path.GetFileName(filename)); filename = Portability.NormalizeDirectorySeparators(filename); try { var testFilenames = new List<string>() { filename }; if (commonFile != null) testFilenames.Add(commonFile); var testDirectoryName = testFolderNameOverride?? TestContext.CurrentContext.Test.FullName.Replace( "." + TestContext.CurrentContext.Test.Name, String.Empty); var testFileDirectory = Path.Combine( ComparisonTest.TestSourceFolder, Path.GetDirectoryName(filename)); var testDirectory = Path.Combine(testFileDirectory, testDirectoryName); Directory.CreateDirectory(testDirectory); using (var test = new ComparisonTest( EvaluatorPool, testFilenames, Path.Combine( testDirectory, ComparisonTest.MapSourceFileToTestFile(Path.GetFileName(filename)) ), stubbedAssemblies, typeInfo, asmCache, compilerOptions: compilerOptions )) { test.GetTestRunnerQueryString = getTestRunnerQueryString ?? test.GetTestRunnerQueryString; result = test.Metacomments; if (extraDependencies != null) { var destDir = Path.GetDirectoryName(test.AssemblyUtility.AssemblyLocation); foreach (var dependency in extraDependencies) File.Copy(dependency, Path.Combine(destDir, Path.GetFileName(dependency)), true); } if (shouldRunJs) { test.Run( makeConfiguration: makeConfiguration, evaluationConfig: evaluationConfig, onTranslationFailure: onTranslationFailure, initializeTranslator: initializeTranslator, scanForProxies: scanForProxies ); } else { Func<string> getJs; long elapsed; try { var csOutput = test.RunCSharp(new string[0], out elapsed); test.GenerateJavascript( new string[0], out getJs, out elapsed, makeConfiguration, evaluationConfig == null || evaluationConfig.ThrowOnUnimplementedExternals, onTranslationFailure, initializeTranslator, shouldWritePrologue: false ); Console.WriteLine("generated"); if (errorCheckPredicate != null) { errorCheckPredicate(csOutput, getJs); } } catch (Exception) { Console.WriteLine("error"); throw; } } } } catch (Exception ex) { if (ex.Message == "JS test failed") Debug.WriteLine(ex.InnerException); else Debug.WriteLine(ex); if (failureList != null) { failureList.Add(Path.GetFileNameWithoutExtension(filename)); } else throw; } return result; }
protected CompileResult RunSingleComparisonTestCase ( object[] parameters, Func<Configuration> makeConfiguration = null, JSEvaluationConfig evaluationConfig = null, Action<Exception> onTranslationFailure = null, string compilerOptions = "", Action<AssemblyTranslator> initializeTranslator = null ) { if (parameters.Length != 5) throw new ArgumentException("Wrong number of test case data parameters."); var provider = (TypeInfoProvider)parameters[1]; var cache = (AssemblyCache)parameters[2]; try { return RunComparisonTest( (string)parameters[0], null, provider, null, null, (string)parameters[3], true, cache, makeConfiguration: makeConfiguration, evaluationConfig: evaluationConfig, onTranslationFailure: onTranslationFailure, compilerOptions: compilerOptions, initializeTranslator: initializeTranslator ); } finally { if ((bool)parameters[4]) { Console.WriteLine("Disposing cache and provider."); if (provider != null) provider.Dispose(); if (cache != null) cache.Dispose(); } } }