public void AllSimpleTests() { var defaultProvider = MakeDefaultProvider(); var simpleTests = Directory.GetFiles( Path.GetFullPath(Path.Combine(ComparisonTest.TestSourceFolder, "SimpleTestCases")), "*.cs" ); var failureList = new List<string>(); foreach (var filename in simpleTests) { Console.Write("// {0} ... ", Path.GetFileName(filename)); try { // We reuse the same type info provider for all the tests in this folder so they run faster using (var test = new ComparisonTest(filename, null, defaultProvider)) test.Run(); } catch (Exception ex) { failureList.Add(Path.GetFileNameWithoutExtension(filename)); if (ex.Message == "JS test failed") Debug.WriteLine(ex.InnerException); else Debug.WriteLine(ex); } } Assert.AreEqual(0, failureList.Count, String.Format("{0} test(s) failed:\r\n{1}", failureList.Count, String.Join("\r\n", failureList.ToArray())) ); }
public void Chars() { using (var test = new ComparisonTest(@"TestCases\Chars.cs")) test.Run(); using (var test = new ComparisonTest(@"TestCases\CharSwitch.cs")) test.Run(); }
public void Casts() { using (var test = new ComparisonTest(@"TestCases\CastToBoolean.cs")) test.Run(); using (var test = new ComparisonTest(@"TestCases\CastingFromNull.cs")) test.Run(); }
public PerformanceAnalysisData(ComparisonTest test, Func <Configuration> makeConfiguration = null) { string trailingOutput; string stderr; string tempS; long tempL; Output = test.RunJavascript( null, out tempS, out tempL, out tempL, out stderr, out trailingOutput, makeConfiguration: makeConfiguration ); var singletonTypeIDs = new HashSet <UInt32>(); TaggedObjectTypesByID = ParseTaggedObjectTypes(stderr, trailingOutput, singletonTypeIDs); TypeInformationByID = ParseTypeInformation(trailingOutput, TaggedObjectTypesByID, singletonTypeIDs); TaggedObjectTypeIDsByName = new Dictionary <string, uint>(TaggedObjectTypesByID.Count); foreach (var kvp in TaggedObjectTypesByID) { if (!TaggedObjectTypeIDsByName.ContainsKey(kvp.Value)) { TaggedObjectTypeIDsByName.Add(kvp.Value, kvp.Key); } } RawStdErr = stderr; RawTypeInformation = trailingOutput; }
public void BinaryTrees() { using (var test = new ComparisonTest(@"TestCases\BinaryTrees.cs")) { test.Run(); test.Run("8"); } }
public void AllXMLTests() { Console.WriteLine("// Spidermonkey has no DOMParser so this test only generates the .js files."); Console.WriteLine("// To run the .js files, click a link below."); Console.WriteLine(); var typeInfo = MakeDefaultProvider(); var testPath = Path.GetFullPath(Path.Combine(ComparisonTest.TestSourceFolder, "XMLTestCases")); var xmlTests = Directory.GetFiles(testPath, "*.cs").Concat(Directory.GetFiles(testPath, "*.vb")).ToArray(); try { RunComparisonTests( xmlTests, null, typeInfo, (testFile) => { Console.WriteLine(ComparisonTest.GetTestRunnerLink(testFile)); return(false); }, (csharpOutput, js) => Console.WriteLine(csharpOutput) ); } catch (Exception exc) { Console.WriteLine(exc.Message); } }
public void CastingFromNull() { using (var test = new ComparisonTest(@"TestCases\CastingFromNull.cs")) { test.Run(); } }
protected string GenericIgnoreTest(string fileName, string workingOutput, string jsErrorSubstring, string[] stubbedAssemblies = null) { long elapsed, temp; string generatedJs = null, jsOutput = null; using (var test = new ComparisonTest(EvaluatorPool, fileName, stubbedAssemblies)) { var csOutput = test.RunCSharp(new string[0], out elapsed); Assert.AreEqual(workingOutput, csOutput.Trim()); try { jsOutput = test.RunJavascript(new string[0], out generatedJs, out temp, out elapsed, MakeConfiguration); Assert.Fail("Expected javascript to throw an exception containing the string \"" + jsErrorSubstring + "\"."); } catch (JavaScriptException jse) { if (!jse.ErrorText.Contains(jsErrorSubstring)) { Console.Error.WriteLine("// Generated JS: \r\n{0}", generatedJs); if (jsOutput != null) { Console.Error.WriteLine("// JS output: \r\n{0}", jsOutput); } throw; } } catch { Console.Error.WriteLine("// Generated JS: \r\n{0}", generatedJs); if (jsOutput != null) { Console.Error.WriteLine("// JS output: \r\n{0}", jsOutput); } throw; } } return(generatedJs); }
public void AllFailingTests() { var testPath = Path.GetFullPath(Path.Combine(ComparisonTest.TestSourceFolder, "FailingTestCases")); var simpleTests = Directory.GetFiles(testPath, "*.cs").Concat(Directory.GetFiles(testPath, "*.vb")).ToArray(); List <string> passedTests = new List <string>(); foreach (var filename in simpleTests) { Console.WriteLine("// {0} ... ", Path.GetFileName(filename)); try { using (var test = MakeTest(filename)) { test.JavascriptExecutionTimeout = 5.0f; test.Run(); Console.WriteLine("// {0}", ComparisonTest.GetTestRunnerLink(test.OutputPath)); } passedTests.Add(Path.GetFileName(filename)); } catch (JavaScriptException jse) { Console.WriteLine(jse.ToString()); } catch (AssertionException ex) { Console.WriteLine(ex.ToString()); } } if (passedTests.Count > 0) { Assert.Fail("One or more tests passed that should have failed:\r\n" + String.Join("\r\n", passedTests)); } }
public void Arithmetic() { using (var test = new ComparisonTest(@"TestCases\IntegerArithmetic.cs")) test.Run(); using (var test = new ComparisonTest(@"TestCases\TernaryArithmetic.cs")) test.Run(); }
public void EscapesOutputFilenames() { using (var test = new ComparisonTest( EvaluatorPool, new[] { @"TestCases\HelloWorld.cs" }, Portability.NormalizeDirectorySeparators(@"MetadataTests\EscapesOutputFilenames") )) { var filenames = test.Translate((tr) => { return((from file in tr.OrderedFiles select file.Filename).ToArray()); }, () => { var configuration = MakeConfiguration(); configuration.FilenameEscapeRegex = "[^A-Za-z0-9 _]"; // We don't escape manifest configuration.SkipManifestCreation = true; return(configuration); }); Assert.AreEqual(1, filenames.Length); foreach (var filename in filenames) { Assert.IsTrue(Regex.IsMatch(filename, @"^([A-Za-z0-9 _]*)\.js$"), "Filename '{0}' does not match regex.", filename); Console.WriteLine(filename); } } }
protected string GenericTest( string fileName, string csharpOutput, string javascriptOutput, string[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null ) { long elapsed, temp; string generatedJs = null; using (var test = new ComparisonTest(EvaluatorPool, Portability.NormalizeDirectorySeparators(fileName), stubbedAssemblies, typeInfo)) { var csOutput = test.RunCSharp(new string[0], out elapsed); try { var jsOutput = test.RunJavascript(new string[0], out generatedJs, out temp, out elapsed, MakeConfiguration); Assert.AreEqual(Portability.NormalizeNewLines(csharpOutput), csOutput.Trim(), "Did not get expected output from C# test"); Assert.AreEqual(Portability.NormalizeNewLines(javascriptOutput), jsOutput.Trim(), "Did not get expected output from JavaScript test"); } catch { Console.Error.WriteLine("// Generated JS: \r\n{0}", generatedJs); throw; } } return(generatedJs); }
public void UnsafeIntPerformanceComparison() { using (var test = MakeTest( @"PerformanceTestCases\UnsafeIntPerformanceComparison.cs" )) { Console.WriteLine("// {0}", ComparisonTest.GetTestRunnerLink(test.OutputPath)); Console.WriteLine(test.RunJavascript(null, MakeUnsafeConfiguration)); } }
public void Enums() { using (var test = new ComparisonTest(@"TestCases\Enums.cs")) test.Run(); using (var test = new ComparisonTest(@"TestCases\EnumArrayLookup.cs")) test.Run(); using (var test = new ComparisonTest(@"TestCases\EnumSwitch.cs")) test.Run(); using (var test = new ComparisonTest(@"TestCases\OverloadWithEnum.cs")) test.Run(); }
public void Vector3() { using (var test = MakeTest( @"PerformanceTestCases\Vector3.cs" )) { Console.WriteLine("// {0}", ComparisonTest.GetTestRunnerLink(test.OutputPath)); long elapsedcs; Console.WriteLine("C#:\r\n{0}", test.RunCSharp(null, out elapsedcs)); Console.WriteLine("JS:\r\n{0}", test.RunJavascript(null, makeConfiguration: MakeUnsafeConfiguration)); } }
public void BaseMethodCalls() { using (var test = MakeTest( @"PerformanceTestCases\BaseMethodCalls.cs" )) { Console.WriteLine("// {0}", ComparisonTest.GetTestRunnerLink(test.OutputPath)); long elapsedcs; Console.WriteLine("C#:\r\n{0}", test.RunCSharp(null, out elapsedcs)); Console.WriteLine("JS:\r\n{0}", test.RunJavascript(null)); } }
protected string GenericIgnoreTest(string fileName, string workingOutput, string jsErrorSubstring, string[] stubbedAssemblies = null) { long elapsed, temp; Func <string> generateJs = null; string jsOutput = null; using (var test = new ComparisonTest(EvaluatorPool, Portability.NormalizeDirectorySeparators(fileName), stubbedAssemblies)) { var csOutput = test.RunCSharp(new string[0], out elapsed); Assert.AreEqual(Portability.NormalizeNewLines(workingOutput), csOutput.Trim()); try { jsOutput = test.RunJavascript(new string[0], out generateJs, out temp, out elapsed, MakeConfiguration); Assert.Fail("Expected javascript to throw an exception containing the string \"" + jsErrorSubstring + "\"."); } catch (JavaScriptEvaluatorException jse) { bool foundMatch = false; foreach (var exc in jse.Exceptions) { if (exc.Message.Contains(jsErrorSubstring)) { foundMatch = true; break; } } if (!foundMatch) { Console.Error.WriteLine("// Was looking for a JS exception containing the string '{0}' but didn't find it.", jsErrorSubstring); Console.Error.WriteLine("// Generated JS: \r\n{0}", generateJs != null ? generateJs() : string.Empty); if (jsOutput != null) { Console.Error.WriteLine("// JS output: \r\n{0}", jsOutput); } throw; } } catch { Console.Error.WriteLine("// Generated JS: \r\n{0}", generateJs != null ? generateJs() : string.Empty); if (jsOutput != null) { Console.Error.WriteLine("// JS output: \r\n{0}", jsOutput); } throw; } } return(generateJs()); }
public void PropertyVsField() { using (var test = MakeTest( @"PerformanceTestCases\PropertyVsField.cs" )) { Console.WriteLine("// {0}", ComparisonTest.GetTestRunnerLink(test.OutputPath)); long elapsedcs; Console.WriteLine("C#:\r\n{0}", test.RunCSharp(null, out elapsedcs)); Console.WriteLine("JS:\r\n{0}", test.RunJavascript( null, makeConfiguration: () => { var cfg = MakeConfiguration(); cfg.CodeGenerator.PreferAccessorMethods = true; return(cfg); } )); } }
public void FixtureSetUp() { var setupCodePath = EvaluatorPool = new EvaluatorPool( ComparisonTest.JSShellPath, JSShellOptions, (e) => { var initCode = ComparisonTest.EvaluatorSetupCode + Environment.NewLine + // When we'll find option to read environment variables in SpiderMonkey, delete this. ComparisonTest.EvaluatorPrepareEnvironmentCode(SetupEvaluatorEnvironment()) + Environment.NewLine + ComparisonTest.EvaluatorRunCode; e.WriteInput(initCode); }, SetupEvaluatorEnvironment() ); }
public void AllFailingTests() { var testPath = Path.GetFullPath(Path.Combine(ComparisonTest.TestSourceFolder, "FailingTestCases")); var simpleTests = Directory.GetFiles(testPath, "*.cs").Concat(Directory.GetFiles(testPath, "*.vb")).ToArray(); int passCount = 0; foreach (var filename in simpleTests) { Console.Write("// {0} ... ", Path.GetFileName(filename)); try { using (var test = new ComparisonTest(filename)) test.Run(); passCount += 1; } catch (Exception ex) { Console.WriteLine("{0}: {1}", ex.GetType().Name, ex.Message); } } Assert.AreEqual(0, passCount, "One or more tests passed that should have failed"); }
public void EscapesOutputFilenames() { using (var test = new ComparisonTest( EvaluatorPool, new[] { @"TestCases\HelloWorld.cs" }, Portability.NormalizeDirectorySeparators(@"MetadataTests\EscapesOutputFilenames") )) { var filenames = test.Translate((tr) => { return (from file in tr.OrderedFiles select file.Filename).ToArray(); }, () => { var configuration = MakeConfiguration(); configuration.FilenameEscapeRegex = "[^A-Za-z0-9 _]"; return configuration; }); Assert.AreEqual(1, filenames.Length); foreach (var filename in filenames) { Assert.IsTrue(Regex.IsMatch(filename, @"^([A-Za-z0-9 _]*)\.js$"), "Filename '{0}' does not match regex.", filename); Console.WriteLine(filename); } } }
public void NBody() { using (var test = new ComparisonTest(@"TestCases\NBody.cs")) { test.Run(); test.Run("300000"); } }
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); }
public void ValueTypeMethods() { using (var test = new ComparisonTest(@"TestCases\ValueTypeMethods.cs")) test.Run(); }
public void Switch() { using (var test = new ComparisonTest(@"TestCases\Switch.cs")) test.Run(); }
public void StaticInitializersInGenericTypesSettingStaticFields() { using (var test = new ComparisonTest(@"TestCases\StaticInitializersInGenericTypesSettingStaticFields.cs")) { test.Run(); } }
public void StaticArrays() { using (var test = new ComparisonTest(@"TestCases\StaticArrayInitializer.cs")) test.Run(); }
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, string compilerOptions = "" ) { 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 )) { result = test.CompileResult; if (shouldRunJs) { test.Run(makeConfiguration: makeConfiguration, onTranslationFailure: onTranslationFailure); } 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, onTranslationFailure); 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 void 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 ) { Console.WriteLine("// {0} ... ", Path.GetFileName(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) ) { if (shouldRunJs) { test.Run(); } 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); Console.WriteLine("generated"); if (errorCheckPredicate != null) { errorCheckPredicate(csOutput, js); } } catch (Exception _exc) { 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; } } }
protected virtual Configuration MakeConfiguration() { return(ComparisonTest.MakeDefaultConfiguration()); }
protected string GetJavascript(string fileName, string expectedText = null) { long elapsed, temp; string generatedJs; using (var test = new ComparisonTest(fileName)) { var output = test.RunJavascript(new string[0], out generatedJs, out temp, out elapsed); if (expectedText != null) Assert.AreEqual(expectedText, output.Trim()); } return generatedJs; }
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); }
protected TypeInfoProvider MakeDefaultProvider() { // Construct a type info provider with default proxies loaded (kind of a hack) return((new AssemblyTranslator(ComparisonTest.MakeDefaultConfiguration())).GetTypeInfoProvider()); }
public void Events() { using (var test = new ComparisonTest(@"TestCases\Events.cs")) test.Run(); }
public void Refs() { using (var test = new ComparisonTest(@"TestCases\RefStruct.cs")) test.Run(); using (var test = new ComparisonTest(@"TestCases\StructPropertyThis.cs")) test.Run(); using (var test = new ComparisonTest(@"TestCases\RefClass.cs")) test.Run(); }
public void FannkuchRedux() { using (var test = new ComparisonTest(@"TestCases\FannkuchRedux.cs")) { test.Run(); test.Run("10"); } }
public void StaticConstructors() { using (var test = new ComparisonTest(@"TestCases\GenericStaticConstructorOrdering.cs")) test.Run(); using (var test = new ComparisonTest(@"TestCases\StaticConstructorOrdering.cs")) test.Run(); using (var test = new ComparisonTest(@"TestCases\StaticInitializersInGenericTypesSettingStaticFields.cs")) test.Run(); }
public void FaultBlock() { using (var test = new ComparisonTest(@"TestCases\FaultBlock.cs")) test.Run(); }
public void StaticInitializersInInheritedClasses() { using (var test = new ComparisonTest(@"TestCases\StaticInitializersInInheritedClasses.cs")) { test.Run(); } }
public void Goto() { using (var test = new ComparisonTest(@"TestCases\Goto.cs")) test.Run(); }
public void Temporaries() { using (var test = new ComparisonTest(@"TestCases\InterleavedTemporaries.cs")) test.Run(); using (var test = new ComparisonTest(@"TestCases\IndirectInterleavedTemporaries.cs")) test.Run(); using (var test = new ComparisonTest(@"TestCases\DirectTemporaryAssignment.cs")) test.Run(); }
public void HelloWorld() { using (var test = new ComparisonTest(@"TestCases\HelloWorld.cs")) { test.Run(); test.Run("hello", "world"); } }
public void YieldReturn() { using (var test = new ComparisonTest(@"TestCases\YieldReturn.cs")) test.Run(); }
public void MulticastDelegates() { using (var test = new ComparisonTest(@"TestCases\MulticastDelegates.cs")) test.Run(); }
protected string GenericTest( string fileName, string csharpOutput, string javascriptOutput, string[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null ) { long elapsed, temp; string generatedJs = null; using (var test = new ComparisonTest(EvaluatorPool, Portability.NormalizeDirectorySeparators(fileName), stubbedAssemblies, typeInfo)) { var csOutput = test.RunCSharp(new string[0], out elapsed); try { var jsOutput = test.RunJavascript(new string[0], out generatedJs, out temp, out elapsed, MakeConfiguration); Assert.AreEqual(Portability.NormalizeNewLines(csharpOutput), csOutput.Trim(), "Did not get expected output from C# test"); Assert.AreEqual(Portability.NormalizeNewLines(javascriptOutput), jsOutput.Trim(), "Did not get expected output from JavaScript test"); } catch { Console.Error.WriteLine("// Generated JS: \r\n{0}", generatedJs); throw; } } return generatedJs; }
protected void RunComparisonTests(string[] filenames, Regex[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null) { foreach (var filename in filenames) { Debug.WriteLine(String.Format("// {0}", filename)); using (var test = new ComparisonTest(filename, stubbedAssemblies, typeInfo)) test.Run(); } }
protected string GenericIgnoreTest(string fileName, string workingOutput, string jsErrorSubstring, string[] stubbedAssemblies = null) { long elapsed, temp; string generatedJs = null, jsOutput = null; using (var test = new ComparisonTest(EvaluatorPool, Portability.NormalizeDirectorySeparators(fileName), stubbedAssemblies)) { var csOutput = test.RunCSharp(new string[0], out elapsed); Assert.AreEqual(workingOutput, csOutput.Trim()); try { jsOutput = test.RunJavascript(new string[0], out generatedJs, out temp, out elapsed, MakeConfiguration); Assert.Fail("Expected javascript to throw an exception containing the string \"" + jsErrorSubstring + "\"."); } catch (JavaScriptEvaluatorException jse) { bool foundMatch = false; foreach (var exc in jse.Exceptions) { if (exc.Message.Contains(jsErrorSubstring)) { foundMatch = true; break; } } if (!foundMatch) { Console.Error.WriteLine("// Was looking for a JS exception containing the string '{0}' but didn't find it.", jsErrorSubstring); Console.Error.WriteLine("// Generated JS: \r\n{0}", generatedJs); if (jsOutput != null) Console.Error.WriteLine("// JS output: \r\n{0}", jsOutput); throw; } } catch { Console.Error.WriteLine("// Generated JS: \r\n{0}", generatedJs); if (jsOutput != null) Console.Error.WriteLine("// JS output: \r\n{0}", jsOutput); throw; } } return generatedJs; }
/// <summary> /// Runs one or more comparison tests by compiling the source C# or VB.net file, /// running the compiled test method, translating the compiled test method to JS, /// then running the translated JS and comparing the outputs. /// </summary> /// <param name="filenames">The path to one or more test files. If a test file is named 'Common.cs' it will be linked into all tests.</param> /// <param name="stubbedAssemblies">The paths of assemblies to stub during translation, if any.</param> /// <param name="typeInfo">A TypeInfoProvider to use for type info. Using this parameter is not advised if you use proxies or JSIL.Meta attributes in your tests.</param> /// <param name="testPredicate">A predicate to invoke before running each test. If the predicate returns false, the JS version of the test will not be run (though it will be translated).</param> protected void RunComparisonTests( string[] filenames, string[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null, Func <string, bool> testPredicate = null, Action <string, string> errorCheckPredicate = null ) { var started = DateTime.UtcNow.Ticks; string commonFile = null; for (var i = 0; i < filenames.Length; i++) { if (filenames[i].Contains("\\Common.")) { commonFile = filenames[i]; break; } } const string keyName = @"Software\Squared\JSIL\Tests\PreviousFailures"; StackFrame callingTest = null; for (int i = 1; i < 10; i++) { callingTest = new StackFrame(i); var method = callingTest.GetMethod(); if ((method != null) && method.GetCustomAttributes(true).Any( (ca) => ca.GetType().FullName == "NUnit.Framework.TestAttribute" )) { break; } else { callingTest = null; } } var previousFailures = new HashSet <string>(); MethodBase callingMethod = null; if ((callingTest != null) && ((callingMethod = callingTest.GetMethod()) != null)) { try { using (var rk = Registry.CurrentUser.CreateSubKey(keyName)) { var names = rk.GetValue(callingMethod.Name) as string; if (names != null) { foreach (var name in names.Split(',')) { previousFailures.Add(name); } } } } catch (Exception ex) { Console.WriteLine("Warning: Could not open registry key: {0}", ex); } } var failureList = new List <string>(); var sortedFilenames = new List <string>(filenames); sortedFilenames.Sort( (lhs, rhs) => { var lhsShort = Path.GetFileNameWithoutExtension(lhs); var rhsShort = Path.GetFileNameWithoutExtension(rhs); int result = (previousFailures.Contains(lhsShort) ? 0 : 1).CompareTo( previousFailures.Contains(rhsShort) ? 0 : 1 ); if (result == 0) { result = lhsShort.CompareTo(rhsShort); } return(result); } ); var asmCache = new AssemblyCache(); foreach (var filename in sortedFilenames) { if (filename == commonFile) { continue; } bool shouldRunJs = true; if (testPredicate != null) { shouldRunJs = testPredicate(filename); } Console.WriteLine("// {0} ... ", Path.GetFileName(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) ) { if (shouldRunJs) { test.Run(); } else { string js; long elapsed; try { var csOutput = test.RunCSharp(new string[0], out elapsed); test.GenerateJavascript(new string[0], out js, out elapsed); Console.WriteLine("ok"); if (errorCheckPredicate != null) { errorCheckPredicate(csOutput, js); } } catch (Exception _exc) { Console.WriteLine("error"); throw; } } } } catch (Exception ex) { failureList.Add(Path.GetFileNameWithoutExtension(filename)); if (ex.Message == "JS test failed") { Debug.WriteLine(ex.InnerException); } else { Debug.WriteLine(ex); } } } if (callingMethod != null) { try { using (var rk = Registry.CurrentUser.CreateSubKey(keyName)) rk.SetValue(callingMethod.Name, String.Join(",", failureList.ToArray())); } catch (Exception ex) { Console.WriteLine("Warning: Could not open registry key: {0}", ex); } } var ended = DateTime.UtcNow.Ticks; var elapsedTotalSeconds = TimeSpan.FromTicks(ended - started).TotalSeconds; Console.WriteLine("// Ran {0} test(s) in {1:000.00}s.", sortedFilenames.Count, elapsedTotalSeconds); Assert.AreEqual(0, failureList.Count, String.Format("{0} test(s) failed:\r\n{1}", failureList.Count, String.Join("\r\n", failureList.ToArray())) ); }