예제 #1
0
        public ComparisonTest(
            EvaluatorPool pool,
            IEnumerable <string> filenames, string outputPath,
            string[] stubbedAssemblies  = null, TypeInfoProvider typeInfo = null,
            AssemblyCache assemblyCache = null, string compilerOptions    = ""
            )
        {
            var started = DateTime.UtcNow.Ticks;

            OutputPath    = outputPath;
            EvaluatorPool = pool;

            var extensions        = (from f in filenames select Path.GetExtension(f).ToLower()).Distinct().ToArray();
            var absoluteFilenames = (from f in filenames select Path.Combine(TestSourceFolder, Portability.NormalizeDirectorySeparators(f)));

            if (extensions.Length != 1)
            {
                throw new InvalidOperationException("Mixture of different source languages provided.");
            }

            var assemblyNamePrefix = Path.GetDirectoryName(outputPath).Split(new char[] { '\\', '/' }).Last();
            var assemblyName       = Path.Combine(
                assemblyNamePrefix,
                Path.GetFileName(outputPath).Replace(".js", "")
                );

            JSFilenames = null;

            switch (extensions[0])
            {
            case ".exe":
            case ".dll":
                var fns = absoluteFilenames.ToArray();
                if (fns.Length > 1)
                {
                    throw new InvalidOperationException("Multiple binary assemblies provided.");
                }

                Assembly = Assembly.LoadFile(fns[0]);
                break;

            case ".js":
                JSFilenames   = absoluteFilenames.ToArray();
                CompileResult = null;
                Assembly      = null;
                break;

            default:
                CompileResult = CompilerUtil.Compile(absoluteFilenames, assemblyName, compilerOptions: compilerOptions);
                Assembly      = CompileResult.Assembly;
                break;
            }

            if (typeInfo != null)
            {
                typeInfo.ClearCaches();
            }

            StubbedAssemblies = stubbedAssemblies;
            TypeInfo          = typeInfo;
            AssemblyCache     = assemblyCache;

            var ended = DateTime.UtcNow.Ticks;

            CompilationElapsed = TimeSpan.FromTicks(ended - started);
        }
예제 #2
0
        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
            )
        {
            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,
                            evaluationConfig: evaluationConfig,
                            onTranslationFailure: onTranslationFailure,
                            initializeTranslator: initializeTranslator
                            );
                    }
                    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);
        }
예제 #3
0
파일: FailingTests.cs 프로젝트: ticuth/JSIL
        public void FailingTestCases(object[] parameters)
        {
            var passed = false;

            var           testFilename        = (string)parameters[0];
            var           translationFailures = new List <Exception>();
            Exception     thrown        = null;
            CompileResult compileResult = null;

            try {
                compileResult = RunSingleComparisonTestCase(
                    parameters,
                    makeConfiguration: () => {
                    var cfg        = MakeConfiguration();
                    cfg.UseThreads = false;
                    return(cfg);
                },
                    onTranslationFailure: (exc) => {
                    lock (translationFailures)
                        translationFailures.Add(exc);
                }
                    );

                passed = true;
            } catch (Exception exc) {
                thrown = exc;
            }

            foreach (var failure in translationFailures)
            {
                Console.WriteLine(failure.ToString());
            }

            if (compileResult != null)
            {
                foreach (var metacomment in compileResult.Metacomments)
                {
                    Console.WriteLine(metacomment);

                    switch (metacomment.Command.ToLower())
                    {
                    case "assertfailurestring":
                        Assert.IsTrue(
                            translationFailures.Any(
                                (f) => f.ToString().Contains(metacomment.Arguments)
                                ),
                            "Expected translation to generate a failure containing the string '" + metacomment.Arguments + "'"
                            );

                        break;

                    case "assertthrows":
                        if ((thrown == null) || (thrown.GetType().Name.ToLower() != metacomment.Arguments.Trim().ToLower()))
                        {
                            Assert.Fail("Expected test to throw an exception of type '" + metacomment.Arguments + "'");
                        }

                        break;

                    case "reference":
                    case "compileroption":
                    case "jsiloption":
                        break;

                    default:
                        throw new NotImplementedException("Command type '" + metacomment.Command + "' not supported in metacomments");
                    }
                }
            }

            Assert.IsFalse(passed, "Test passed when it should have failed");
        }