コード例 #1
0
ファイル: DeadCodeAnalyzer.cs プロジェクト: Don191/JSIL
        public void Analyze(TypeInfoProvider typeInfoProvider) {
            if (!Configuration.DeadCodeElimination.GetValueOrDefault(false))
                return;

            deadCodeInfo.TypeInfoProvider = typeInfoProvider;

            stopwatchElapsed = new Stopwatch();
            stopwatchElapsed.Start();

            var foundEntrypoints = from assembly in assemblyDefinitions
                                   from modules in assembly.Modules
                                   where modules.EntryPoint != null
                                   select modules.EntryPoint;

            deadCodeInfo.AddAssemblies(assemblyDefinitions);


            foreach (MethodDefinition method in foundEntrypoints)
            {
                deadCodeInfo.WalkMethod(method);
            }

            deadCodeInfo.ResolveVirtualMethodsCycle();

            stopwatchElapsed.Stop();
            Console.WriteLine("// Dead code analysis took {0} ms", stopwatchElapsed.ElapsedMilliseconds);
        }
コード例 #2
0
        static AssemblyTranslator CreateTranslator(
            Configuration configuration, AssemblyManifest manifest, AssemblyCache assemblyCache
            )
        {
            TypeInfoProvider typeInfoProvider = null;

            Console.Error.WriteLine(
                "// Using .NET framework {0} in {1} GC mode. Tuned GC {2}.",
                Environment.Version.ToString(),
                System.Runtime.GCSettings.IsServerGC ? "server" : "workstation",
#if TARGETTING_FX_4_5
                configuration.TuneGarbageCollection.GetValueOrDefault(true) ? "enabled" : "disabled"
#else
                "disabled (must be built in .NET 4.5 mode)"
#endif
                );

            if (
                configuration.ReuseTypeInfoAcrossAssemblies.GetValueOrDefault(true) &&
                (CachedTypeInfoProvider != null)
                )
            {
                if (CachedTypeInfoProviderConfiguration.Assemblies.Equals(configuration.Assemblies))
                {
                    typeInfoProvider = CachedTypeInfoProvider;
                }
            }

            var translator = new AssemblyTranslator(
                configuration, typeInfoProvider, manifest, assemblyCache,
                onProxyAssemblyLoaded: (name, classification) =>
                Console.Error.WriteLine("// Loaded proxies from '{0}'", ShortenPath(name))
                );

            translator.Decompiling       += MakeProgressHandler("Decompiling ");
            translator.RunningTransforms += MakeProgressHandler("Translating ");
            translator.Writing           += MakeProgressHandler("Writing JS  ");

            translator.AssemblyLoaded += (fn, classification) =>
                                         Console.Error.WriteLine("// Loaded {0} ({1})", ShortenPath(fn), classification);
            translator.CouldNotLoadSymbols     += (fn, ex) => {
            };
            translator.CouldNotResolveAssembly += (fn, ex) =>
                                                  Console.Error.WriteLine("// Could not load module {0}: {1}", fn, ex.Message);
            translator.CouldNotDecompileMethod += (fn, ex) =>
                                                  Console.Error.WriteLine("// Could not decompile method {0}: {1}", fn, ex);

            if (typeInfoProvider == null)
            {
                if (CachedTypeInfoProvider != null)
                {
                    CachedTypeInfoProvider.Dispose();
                }

                CachedTypeInfoProvider = translator.GetTypeInfoProvider();
                CachedTypeInfoProviderConfiguration = configuration;
            }

            return(translator);
        }
コード例 #3
0
        protected TypeInfoProvider MakeDefaultProvider () {
            if (DefaultTypeInfoProvider == null)
                // Construct a type info provider with default proxies loaded (kind of a hack)
                DefaultTypeInfoProvider = (new AssemblyTranslator(MakeConfiguration())).GetTypeInfoProvider();

            return DefaultTypeInfoProvider.Clone();
        }
コード例 #4
0
ファイル: TestUtil.cs プロジェクト: carcer/JSIL
        protected IEnumerable <TestCaseData> FolderTestSource(string folderName, TypeInfoProvider typeInfo = null, AssemblyCache asmCache = null)
        {
            var testPath  = Path.GetFullPath(Path.Combine(ComparisonTest.TestSourceFolder, folderName));
            var testNames = Directory.GetFiles(testPath, "*.cs").Concat(Directory.GetFiles(testPath, "*.vb")).OrderBy((s) => s);

            string commonFile = null;

            foreach (var testName in testNames)
            {
                if (Path.GetFileNameWithoutExtension(testName) == "Common")
                {
                    commonFile = testName;
                    break;
                }
            }

            foreach (var testName in testNames)
            {
                if (Path.GetFileNameWithoutExtension(testName) == "Common")
                {
                    continue;
                }

                yield return((new TestCaseData(new object[] { new object[] { testName, typeInfo, asmCache, commonFile } }))
                             .SetName(Path.GetFileName(testName))
                             .SetDescription(String.Format("{0}\\{1}", folderName, Path.GetFileName(testName)))
                             .SetCategory(folderName));
            }
        }
コード例 #5
0
ファイル: DeadCodeAnalyzer.cs プロジェクト: ticuth/JSIL
        public void Analyze(TypeInfoProvider typeInfoProvider)
        {
            if (!Configuration.DeadCodeElimination.GetValueOrDefault(false))
            {
                return;
            }

            deadCodeInfo.TypeInfoProvider = typeInfoProvider;

            stopwatchElapsed = new Stopwatch();
            stopwatchElapsed.Start();

            var foundEntrypoints = from assembly in assemblyDefinitions
                                   from modules in assembly.Modules
                                   where modules.EntryPoint != null
                                   select modules.EntryPoint;

            deadCodeInfo.AddAssemblies(assemblyDefinitions);


            foreach (MethodDefinition method in foundEntrypoints)
            {
                deadCodeInfo.WalkMethod(method);
            }

            deadCodeInfo.ResolveVirtualMethodsCycle();

            stopwatchElapsed.Stop();
            Console.WriteLine("// Dead code analysis took {0} ms", stopwatchElapsed.ElapsedMilliseconds);
        }
コード例 #6
0
        public IExcelMapper Build(IWorkbook workbook, MapperSettings settings)
        {
            if (workbook == null)
            {
                throw new ArgumentNullException(nameof(workbook));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            IConverterProvider      converterProvider      = GetDefaultConvertersProvider();
            IPropertyNameConvention propertyNameConvention = GetDefaultPropertyNamingConventions();

            if (settings.Convention.AnyValue())
            {
                propertyNameConvention = settings.Convention;
            }

            if (settings.ConverterProvider.AnyValue())
            {
                converterProvider = settings.ConverterProvider;
            }

            var propertiesExtractor   = new TypeInfoProvider();
            var propertyInfoExtractor = new PropertyInfoExtractor();
            var propertiesMapFactory  = new ExcelPropertyMapFactory(propertiesExtractor, propertyInfoExtractor,
                                                                    propertyNameConvention, _loggerFactory.CreateLogger <ExcelPropertyMapFactory>());

            var typeConverter = new CellValueConverter(converterProvider);
            var modelFactory  = new ModelBuilder(propertyInfoExtractor);

            return(new ExcelMapper(workbook, propertiesMapFactory, typeConverter, modelFactory,
                                   _loggerFactory.CreateLogger <ExcelMapper>()));
        }
コード例 #7
0
ファイル: IntroduceEnumCasts.cs プロジェクト: wdstest/SharpJS
        public IntroduceEnumCasts(
            TypeSystem typeSystem, JSSpecialIdentifiers js,
            TypeInfoProvider typeInfo, MethodTypeFactory methodTypes,
            IFunctionSource functionSource
            )
        {
            TypeSystem     = typeSystem;
            TypeInfo       = typeInfo;
            MethodTypes    = methodTypes;
            JS             = js;
            FunctionSource = functionSource;

            LogicalOperators = new HashSet <JSOperator>()
            {
                JSOperator.LogicalAnd,
                JSOperator.LogicalOr,
                JSOperator.LogicalNot
            };

            BitwiseOperators = new HashSet <JSOperator>()
            {
                JSOperator.BitwiseAnd,
                JSOperator.BitwiseOr,
                JSOperator.BitwiseXor
            };
        }
コード例 #8
0
ファイル: Util.cs プロジェクト: Caspeco/JSIL
        public ComparisonTest(string filename, string[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null)
        {
            Filename = Path.Combine(TestSourceFolder, filename);

            var sourceCode = File.ReadAllText(Filename);
            switch (Path.GetExtension(filename).ToLower()) {
                case ".cs":
                    Assembly = CompilerUtil.CompileCS(sourceCode, out TemporaryFiles);
                    break;
                case ".vb":
                    Assembly = CompilerUtil.CompileVB(sourceCode, out TemporaryFiles);
                    break;
                default:
                    throw new ArgumentException("Unsupported source file type for test");
            }

            var program = Assembly.GetType("Program");
            if (program == null)
                throw new Exception("Test missing 'Program' main class");

            TestMethod = program.GetMethod("Main");
            if (TestMethod == null)
                throw new Exception("Test missing 'Main' method of 'Program' main class");

            StubbedAssemblies = stubbedAssemblies;
            TypeInfo = typeInfo;
        }
コード例 #9
0
ファイル: DeadCodeAnalyzer.cs プロジェクト: cbsistem/JSIL
        public void Analyze (AssemblyTranslator translator, AssemblyDefinition[] assemblies, TypeInfoProvider typeInfoProvider) {
            if (!Configuration.DeadCodeElimination)
                return;

            assemblyDefinitions.Clear();
            assemblyDefinitions.AddRange(assemblies);

            deadCodeInfo.TypeInfoProvider = typeInfoProvider;

            stopwatchElapsed = new Stopwatch();
            stopwatchElapsed.Start();

            var foundEntrypoints = from assembly in assemblyDefinitions
                                   from modules in assembly.Modules
                                   where modules.EntryPoint != null
                                   select modules.EntryPoint;

            deadCodeInfo.AddAssemblies(assemblyDefinitions);


            foreach (MethodDefinition method in foundEntrypoints)
            {
                deadCodeInfo.WalkMethod(method);
            }

            deadCodeInfo.FinishProcessing();

            stopwatchElapsed.Stop();
            Console.WriteLine("// Dead code analysis took {0} ms", stopwatchElapsed.ElapsedMilliseconds);
        }
コード例 #10
0
 public static void Setup(TestContext context)
 {
     TypeInfoProvider.GetGlobal().AddFunction("print", (a) => {
         context.WriteLine((string)a[0]);
         return(null);
     }, null, new Type[] { typeof(string) });
 }
コード例 #11
0
ファイル: MainForm.cs プロジェクト: degagetech/AgilityConfig
 private void BuildConfigurableItemTreeView(IEnumerable <ConfigurableItem> items)
 {
     foreach (var item in items)
     {
         if (!File.Exists(item.Path))
         {
             continue;
         }
         Type type = null;
         try
         {
             type = TypeInfoProvider.GetType(item.Type);
             if (type == null)
             {
                 continue;
             }
             item.type = type;
             TreeNode node = new TreeNode();
             node.Text        = item.Name;
             node.ToolTipText = item.Path;
             node.Tag         = item;
             this._tvConfigCatalog.Nodes.Add(node);
         }
         catch { }
     }
 }
コード例 #12
0
ファイル: GenericTestFixture.cs プロジェクト: sihugh/JSIL
        protected IEnumerable <TestCaseData> FilenameTestSource(string[] filenames, TypeInfoProvider typeInfo = null, AssemblyCache asmCache = null)
        {
            var testNames = filenames.OrderBy((s) => s).ToArray();

            for (int i = 0, l = testNames.Length; i < l; i++)
            {
                var testName = testNames[i];

                bool isIgnored      = testName.StartsWith("ignored:", StringComparison.OrdinalIgnoreCase);
                var  actualTestName = testName;

                if (isIgnored)
                {
                    actualTestName = actualTestName.Substring(actualTestName.IndexOf(":") + 1);
                }

                var item = (new TestCaseData(new object[] { new object[] { actualTestName, typeInfo, asmCache, null, i == (l - 1) } }))
                           .SetName(PickTestNameForFilename(actualTestName));

                if (isIgnored)
                {
                    item.Ignore();
                }

                yield return(item);
            }
        }
コード例 #13
0
ファイル: GenericTestFixture.cs プロジェクト: sihugh/JSIL
        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);
        }
コード例 #14
0
        protected void AddTypeInfoMapping(IMap <String, ITypeInfoItem> typeInfoMap, IValueObjectConfig config, String boMemberName, StringBuilder sb)
        {
            String        voMemberName = config.GetValueObjectMemberName(boMemberName);
            ITypeInfoItem voMember     = TypeInfoProvider.GetHierarchicMember(config.ValueType, voMemberName);

            if (voMember == null)
            {
                return;
            }
            typeInfoMap.Put(boMemberName, voMember);
            if (sb == null)
            {
                return;
            }
            sb.Length = 0;
            String        voSpecifiedName   = sb.Append(voMemberName).Append("Specified").ToString();
            ITypeInfoItem voSpecifiedMember = TypeInfoProvider.GetHierarchicMember(config.ValueType, voSpecifiedName);

            if (voSpecifiedMember == null)
            {
                return;
            }
            sb.Length = 0;
            String boSpecifiedName = sb.Append(boMemberName).Append("Specified").ToString();

            typeInfoMap.Put(boSpecifiedName, voSpecifiedMember);
        }
コード例 #15
0
        public void Parsing()
        {
            Enviroment enviroment = new Enviroment(TypeInfoProvider.GetGlobal());
            var        block      = TokenParser.Parse("\"Comment\" .\nprint IN string 25 . .\nprint IN add \"Hello\" \"world\" . .\n  mul 5 10 , string , add \" = 25\" , print .", enviroment, CodePosition.GetExternal());
            var        statements = block.GetSyntaxNodes();

            Assert.AreEqual(statements.Count, 4);
        }
コード例 #16
0
 public EmulateStructAssignment(QualifiedMemberIdentifier member, IFunctionSource functionSource, TypeSystem typeSystem, TypeInfoProvider typeInfo, CLRSpecialIdentifiers clr, bool optimizeCopies)
     : base(member, functionSource)
 {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
     CLR = clr;
     OptimizeCopies = optimizeCopies;
 }
コード例 #17
0
 public EmulateStructAssignment(TypeSystem typeSystem, IFunctionSource functionSource, TypeInfoProvider typeInfo, CLRSpecialIdentifiers clr, bool optimizeCopies)
 {
     TypeSystem = typeSystem;
     FunctionSource = functionSource;
     TypeInfo = typeInfo;
     CLR = clr;
     OptimizeCopies = optimizeCopies;
 }
コード例 #18
0
        public void AddFunctionTest()
        {
            TypeInfoProvider provider = new TypeInfoProvider();

            provider.AddFunction("test", (v) => v, typeof(void), new Type[] { });

            Assert.IsNotNull(provider.GetFunction("test"));
        }
コード例 #19
0
        /// <summary>
        /// Initializes a new instance of the ApplicationSettingsGenericStorage&lt;T&gt; class.
        /// </summary>
        /// <param name="settingsProperty">The member expression specifying application
        /// settings property to be used for storing settings object.</param>
        public ApplicationSettingsGenericStorage(
            Expression <Func <Properties.Settings, string> > settingsProperty)
        {
            Debug.Assert(settingsProperty != null);

            _storageProperty = TypeInfoProvider <Properties.Settings> .GetPropertyInfo(
                settingsProperty);
        }
コード例 #20
0
ファイル: CacheSignatures.cs プロジェクト: wushian/JSIL
 public SignatureCacher(TypeInfoProvider typeInfo, bool localCachingEnabled)
 {
     LocalCachedSets = new Dictionary <MemberIdentifier, CacheSet>(
         new MemberIdentifier.Comparer(typeInfo)
         );
     VisitNestedFunctions = true;
     LocalCachingEnabled  = localCachingEnabled;
 }
コード例 #21
0
ファイル: ComparisonTest.cs プロジェクト: thompsonbill/JSIL
        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", "")
                );

            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;

            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);
        }
コード例 #22
0
        public virtual void AfterPropertiesSet()
        {
            ParamChecker.AssertNotNull(EntityType, "EntityType");
            ParamChecker.AssertNotNull(FilterMember, "FilterMember");

            // It is intentended to have no null check for ModelContainer, because the class can be used without it!

            typeInfoItem = TypeInfoProvider.GetHierarchicMember(EntityType, FilterMember);
        }
コード例 #23
0
        /// <summary>
        /// Creates a new instance of the <see cref="RouteAssociationTracker"/> class.
        /// </summary>
        /// <typeparam name="TProperty">The type of the Route property to track association
        /// with.</typeparam>
        /// <param name="expression">The member expression specifying Route property to
        /// track.</param>
        /// <returns>A new instance of the <see cref="RouteAssociationTracker"/> class for the
        /// specified Route property.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="expression"/> is
        /// a null reference.</exception>
        /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="expression"/> node
        /// type is not <see cref="ExpressionType.MemberAccess"/>.</exception>
        public static RouteAssociationTracker Create <TProperty>(
            Expression <Func <Route, TProperty> > expression)
        {
            CodeContract.RequiresNotNull("expression", expression);

            var propertyInfo = TypeInfoProvider <Route> .GetPropertyInfo(expression);

            return(new RouteAssociationTracker(propertyInfo));
        }
コード例 #24
0
        public void VariableRedefinitionFail()
        {
            Enviroment enviroment = new Enviroment(TypeInfoProvider.GetGlobal());

            enviroment.StartBlock(CodePosition.GetExternal());
            enviroment.DefineVariable("x", typeof(int), CodePosition.GetExternal());
            enviroment.DefineVariable("x", typeof(int), CodePosition.GetExternal());
            enviroment.EndBlock();
        }
コード例 #25
0
        public void VariableTypeSafetyInCode()
        {
            Enviroment enviroment = new Enviroment(TypeInfoProvider.GetGlobal());

            enviroment.StartBlock(CodePosition.GetExternal());
            enviroment.DefineVariable("x", typeof(string), CodePosition.GetExternal());
            TokenParser.Parse("x= 0 .", enviroment, CodePosition.GetExternal());
            enviroment.EndBlock();
        }
コード例 #26
0
 public DecomposeMutationOperators (
     TypeSystem typeSystem, TypeInfoProvider typeInfo, 
     IFunctionSource functionSource, bool decomposeAllMutations
 ) {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
     FunctionSource = functionSource;
     DecomposeAllMutations = decomposeAllMutations;
 }
コード例 #27
0
        public void RunTheExampleFile()
        {
            var        text       = System.IO.File.ReadAllText("../../../Examples/example.ws");
            Enviroment enviroment = new Enviroment(TypeInfoProvider.GetGlobal());
            var        block      = TokenParser.Parse(text, enviroment, CodePosition.GetExternal());

            block.Validate(enviroment);
            Assert.AreEqual(typeof(string), block.ReturnType);
            Assert.AreEqual("aaaab", block.Evaluate());
        }
コード例 #28
0
ファイル: GenericTestFixture.cs プロジェクト: sihugh/JSIL
        protected TypeInfoProvider MakeDefaultProvider()
        {
            if (DefaultTypeInfoProvider == null)
            {
                // Construct a type info provider with default proxies loaded (kind of a hack)
                DefaultTypeInfoProvider = (new AssemblyTranslator(MakeConfiguration())).GetTypeInfoProvider();
            }

            return(DefaultTypeInfoProvider.Clone());
        }
コード例 #29
0
        public void VariableDefinition()
        {
            Enviroment enviroment = new Enviroment(TypeInfoProvider.GetGlobal());

            enviroment.StartBlock(CodePosition.GetExternal());
            Assert.IsNull(enviroment.GetVariable("y"));
            enviroment.DefineVariable("x", typeof(int), CodePosition.GetExternal());
            Assert.IsNotNull(enviroment.GetVariable("x"));
            enviroment.EndBlock();
        }
コード例 #30
0
 public DecomposeMutationOperators(
     TypeSystem typeSystem, TypeInfoProvider typeInfo,
     IFunctionSource functionSource, bool decomposeAllMutations
     )
 {
     TypeSystem            = typeSystem;
     TypeInfo              = typeInfo;
     FunctionSource        = functionSource;
     DecomposeAllMutations = decomposeAllMutations;
 }
コード例 #31
0
ファイル: IntroduceEnumCasts.cs プロジェクト: Caspeco/JSIL
        public IntroduceEnumCasts(TypeSystem typeSystem, TypeInfoProvider typeInfo)
        {
            TypeSystem = typeSystem;
            TypeInfo = typeInfo;

            LogicalOperators = new HashSet<JSOperator>() {
                JSOperator.LogicalAnd,
                JSOperator.LogicalOr,
                JSOperator.LogicalNot
            };
        }
コード例 #32
0
ファイル: GenericTestFixture.cs プロジェクト: cbsistem/JSIL
 protected ComparisonTest MakeTest (
     string filename, string[] stubbedAssemblies = null,
     TypeInfoProvider typeInfo = null,
     AssemblyCache assemblyCache = null
 ) {
     return new ComparisonTest(
         EvaluatorPool,
         Portability.NormalizeDirectorySeparators(filename), stubbedAssemblies,
         typeInfo, assemblyCache
     );
 }
コード例 #33
0
ファイル: GenericTestFixture.cs プロジェクト: cbsistem/JSIL
        public void Dispose () {
            if (EvaluatorPool != null) {
                EvaluatorPool.Dispose();
                EvaluatorPool = null;
            }

            if (DefaultTypeInfoProvider != null) {
                DefaultTypeInfoProvider.Dispose();
                DefaultTypeInfoProvider = null;
            }
        }
コード例 #34
0
ファイル: TestUtil.cs プロジェクト: carcer/JSIL
 protected ComparisonTest MakeTest(
     string filename, string[] stubbedAssemblies = null,
     TypeInfoProvider typeInfo   = null,
     AssemblyCache assemblyCache = null
     )
 {
     return(new ComparisonTest(
                EvaluatorPool,
                filename, stubbedAssemblies,
                typeInfo, assemblyCache
                ));
 }
コード例 #35
0
ファイル: AssemblyTranslator.cs プロジェクト: nowonu/JSIL
        public AssemblyTranslator(TypeInfoProvider typeInfoProvider = null)
        {
            // Important to avoid preserving the proxy list from previous translations in this process
            MemberIdentifier.ResetProxies();

            if (typeInfoProvider != null) {
                TypeInfoProvider = typeInfoProvider;
            } else {
                TypeInfoProvider = new JSIL.TypeInfoProvider();
                AddProxyAssembly(typeof(JSIL.Proxies.ObjectProxy).Assembly, false);
            }
        }
コード例 #36
0
        public void VariablesInCode()
        {
            Enviroment enviroment = new Enviroment(TypeInfoProvider.GetGlobal());

            enviroment.StartBlock(CodePosition.GetExternal());
            enviroment.DefineVariable("x", typeof(int), CodePosition.GetExternal());
            TokenParser.Parse("DEFINE:y:int . &y . y= 0 . &x . x= &y .", enviroment, CodePosition.GetExternal(), true);

            Assert.IsNotNull(enviroment.GetVariable("y"));
            Assert.AreEqual(enviroment.GetVariable("y").Type, typeof(int));
            enviroment.EndBlock();
        }
コード例 #37
0
ファイル: Program.cs プロジェクト: dosh1974/JSIL
        static AssemblyTranslator CreateTranslator(
            Configuration configuration, AssemblyManifest manifest, AssemblyCache assemblyCache
            )
        {
            TypeInfoProvider typeInfoProvider = null;

            if (
                configuration.ReuseTypeInfoAcrossAssemblies.GetValueOrDefault(true) &&
                (CachedTypeInfoProvider != null)
                )
            {
                if (CachedTypeInfoProviderConfiguration.Assemblies.Equals(configuration.Assemblies))
                {
                    typeInfoProvider = CachedTypeInfoProvider;
                }
            }

            var translator = new AssemblyTranslator(
                configuration, typeInfoProvider, manifest, assemblyCache,
                onProxyAssemblyLoaded: (name, classification) => {
                Console.Error.WriteLine("// Loaded proxies from '{0}'", ShortenPath(name));
            }
                );

            translator.Decompiling       += MakeProgressHandler("Decompiling ");
            translator.RunningTransforms += MakeProgressHandler("Translating ");
            translator.Writing           += MakeProgressHandler("Writing JS  ");

            translator.AssemblyLoaded += (fn, classification) => {
                Console.Error.WriteLine("// Loaded {0} ({1})", ShortenPath(fn), classification);
            };
            translator.CouldNotLoadSymbols     += (fn, ex) => {
            };
            translator.CouldNotResolveAssembly += (fn, ex) => {
                Console.Error.WriteLine("// Could not load module {0}: {1}", fn, ex.Message);
            };
            translator.CouldNotDecompileMethod += (fn, ex) => {
                Console.Error.WriteLine("// Could not decompile method {0}: {1}", fn, ex.Message);
            };

            if (typeInfoProvider == null)
            {
                if (CachedTypeInfoProvider != null)
                {
                    CachedTypeInfoProvider.Dispose();
                }

                CachedTypeInfoProvider = translator.GetTypeInfoProvider();
                CachedTypeInfoProviderConfiguration = configuration;
            }

            return(translator);
        }
コード例 #38
0
ファイル: FastInserter.cs プロジェクト: klym1/FastInsert
        public static async Task FastInsertAsync(this IDbConnection connection,
                                                 IEnumerable <object> list,
                                                 Type entityType,
                                                 Action <FastInsertConfig>?conf = null)
        {
            EnsureMySqlConnection(connection);

            var config = GetConfig(conf, entityType);

            if (!ConnectionStringValidator.ConnectionStringValid(connection.ConnectionString, out var error))
            {
                throw new ArgumentException(error);
            }

            var tableName = config.TableNameResolver.GetTableName();

            var writer   = CsvWriterConfigurator.GetWriter(entityType, config.BinaryFormat);
            var tableDef = TypeInfoProvider.GetClassFields(entityType, config.BinaryFormat).ToList();

            foreach (var partition in EnumerableExtensions.GetPartitions(list, config.BatchSize))
            {
                var fileName = $"{Guid.NewGuid()}.csv";

                try
                {
                    var csvSettings = new CsvFileSettings
                                      (
                        delimiter: ";;",
                        lineEnding: Environment.NewLine,
                        path: fileName,
                        fieldEscapedByChar: "\\\\",
                        fieldEnclosedByChar: ""
                                      );

                    var query = BuildLoadDataQuery.BuildQuery(tableName, tableDef, csvSettings);

                    await writer.WriteAsync(partition, csvSettings);

                    await connection.ExecuteAsync(query);
                }
                finally
                {
                    if (config?.Writer != null)
                    {
                        await config.Writer.WriteLineAsync(fileName + ":");

                        await config.Writer.WriteLineAsync(File.ReadAllText(fileName));
                    }

                    File.Delete(fileName);
                }
            }
        }
コード例 #39
0
ファイル: GenericTestFixture.cs プロジェクト: sihugh/JSIL
 protected ComparisonTest MakeTest(
     string filename, string[] stubbedAssemblies = null,
     TypeInfoProvider typeInfo   = null,
     AssemblyCache assemblyCache = null
     )
 {
     return(new ComparisonTest(
                EvaluatorPool,
                Portability.NormalizeDirectorySeparators(filename), stubbedAssemblies,
                typeInfo, assemblyCache
                ));
 }
コード例 #40
0
ファイル: Util.cs プロジェクト: robashton/JSIL
        public ComparisonTest(string filename, Regex[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null)
        {
            Filename = Path.Combine(TestSourceFolder, filename);

            var sourceCode = File.ReadAllText(Filename);
            Assembly = CSharpUtil.Compile(sourceCode, out TemporaryFiles);

            TestMethod = Assembly.GetType("Program").GetMethod("Main");

            StubbedAssemblies = stubbedAssemblies;
            TypeInfo = typeInfo;
        }
コード例 #41
0
ファイル: TestUtil.cs プロジェクト: xen2/JSIL
        public ComparisonTest(
            EvaluatorPool pool,
            IEnumerable<string> filenames, string outputPath, 
            string[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null,
            AssemblyCache assemblyCache = null
        )
        {
            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, 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", "")
            );

            switch (extensions[0]) {
                case ".cs":
                    Assembly = CompilerUtil.CompileCS(absoluteFilenames, assemblyName);
                    break;
                case ".vb":
                    Assembly = CompilerUtil.CompileVB(absoluteFilenames, assemblyName);
                    break;
                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;
                default:
                    throw new ArgumentException("Unsupported source file type for test");
            }

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

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

            var ended = DateTime.UtcNow.Ticks;
            CompilationElapsed = TimeSpan.FromTicks(ended - started);
        }
コード例 #42
0
ファイル: TestUtil.cs プロジェクト: xen2/JSIL
 public ComparisonTest(
     EvaluatorPool pool, 
     string filename, string[] stubbedAssemblies = null, 
     TypeInfoProvider typeInfo = null, AssemblyCache assemblyCache = null
 )
     : this(pool,
         new[] { filename }, 
         Path.Combine(
             TestSourceFolder,
             MapSourceFileToTestFile(filename)
         ), 
         stubbedAssemblies, typeInfo, assemblyCache)
 {
 }
コード例 #43
0
ファイル: IntroduceEnumCasts.cs プロジェクト: xen2/JSIL
        public IntroduceEnumCasts(TypeSystem typeSystem, JSSpecialIdentifiers js, TypeInfoProvider typeInfo, MethodTypeFactory methodTypes)
        {
            TypeSystem  = typeSystem;
            TypeInfo    = typeInfo;
            MethodTypes = methodTypes;
            JS          = js;

            LogicalOperators = new HashSet <JSOperator>()
            {
                JSOperator.LogicalAnd,
                JSOperator.LogicalOr,
                JSOperator.LogicalNot
            };
        }
コード例 #44
0
ファイル: GenericTestFixture.cs プロジェクト: sihugh/JSIL
        public void Dispose()
        {
            if (EvaluatorPool != null)
            {
                EvaluatorPool.Dispose();
                EvaluatorPool = null;
            }

            if (DefaultTypeInfoProvider != null)
            {
                DefaultTypeInfoProvider.Dispose();
                DefaultTypeInfoProvider = null;
            }
        }
コード例 #45
0
ファイル: IntroduceEnumCasts.cs プロジェクト: Don191/JSIL
        public IntroduceEnumCasts (TypeSystem typeSystem, JSSpecialIdentifiers js, TypeInfoProvider typeInfo, MethodTypeFactory methodTypes) {
            TypeSystem = typeSystem;
            TypeInfo = typeInfo;
            MethodTypes = methodTypes;
            JS = js;

            LogicalOperators = new HashSet<JSOperator>() {
                JSOperator.LogicalAnd,
                JSOperator.LogicalOr,
                JSOperator.LogicalNot
            };

            BitwiseOperators = new HashSet<JSOperator>() {
                JSOperator.BitwiseAnd,
                JSOperator.BitwiseOr,
                JSOperator.BitwiseXor
            };
        }
コード例 #46
0
ファイル: Program.cs プロジェクト: snuderl/JSIL
        static AssemblyTranslator CreateTranslator(
            Configuration configuration, AssemblyManifest manifest, AssemblyCache assemblyCache
        )
        {
            TypeInfoProvider typeInfoProvider = null;

            if (
                configuration.ReuseTypeInfoAcrossAssemblies.GetValueOrDefault(true) &&
                (CachedTypeInfoProvider != null)
            ) {
                if (CachedTypeInfoProviderConfiguration.Assemblies.Equals(configuration.Assemblies))
                    typeInfoProvider = CachedTypeInfoProvider;
            }

            var translator = new AssemblyTranslator(configuration, typeInfoProvider, manifest, assemblyCache);

            translator.Decompiling += MakeProgressHandler("Decompiling   ");
            translator.Optimizing += MakeProgressHandler ("Optimizing    ");
            translator.Writing += MakeProgressHandler    ("Generating JS ");

            translator.AssemblyLoaded += (fn) => {
                Console.Error.WriteLine("// Loaded {0}", ShortenPath(fn));
            };
            translator.CouldNotLoadSymbols += (fn, ex) => {
            };
            translator.CouldNotResolveAssembly += (fn, ex) => {
                Console.Error.WriteLine("// Could not load module {0}: {1}", fn, ex.Message);
            };
            translator.CouldNotDecompileMethod += (fn, ex) => {
                Console.Error.WriteLine("// Could not decompile method {0}: {1}", fn, ex.Message);
            };

            if (typeInfoProvider == null) {
                if (CachedTypeInfoProvider != null)
                    CachedTypeInfoProvider.Dispose();

                CachedTypeInfoProvider = translator.GetTypeInfoProvider();
                CachedTypeInfoProviderConfiguration = configuration;
            }

            return translator;
        }
コード例 #47
0
ファイル: GenericTestFixture.cs プロジェクト: Ocelloid/JSIL
        protected IEnumerable<TestCaseData> FilenameTestSource(string[] filenames, TypeInfoProvider typeInfo = null, AssemblyCache asmCache = null)
        {
            var testNames = filenames.OrderBy((s) => s).ToArray();

            for (int i = 0, l = testNames.Length; i < l; i++) {
                var testName = testNames[i];

                bool isIgnored = testName.StartsWith("ignored:", StringComparison.OrdinalIgnoreCase);
                var actualTestName = testName;

                if (isIgnored)
                    actualTestName = actualTestName.Substring(actualTestName.IndexOf(":") + 1);

                var item = (new TestCaseData(new object[] { new object[] { actualTestName, typeInfo, asmCache, null, i == (l - 1) } }))
                    .SetName(Path.GetFileName(actualTestName));

                if (isIgnored)
                    item.Ignore();

                yield return item;
            }
        }
コード例 #48
0
ファイル: GenericTestFixture.cs プロジェクト: cbsistem/JSIL
        protected IEnumerable<TestCaseData> FilenameTestSource (string[] filenames, TypeInfoProvider typeInfo = null, AssemblyCache asmCache = null, bool markLastTest = true) {
            var testNames = filenames.OrderBy((s) => s).ToArray();

            for (int i = 0, l = testNames.Length; i < l; i++) {
                var testName = testNames[i];

                bool isIgnored = testName.StartsWith("ignored:", StringComparison.OrdinalIgnoreCase);
                var actualTestName = testName;

                if (isIgnored)
                    actualTestName = actualTestName.Substring(actualTestName.IndexOf(":") + 1);

                var item = (new TestCaseData(new object[] { new object[] { actualTestName, typeInfo, asmCache, null, markLastTest && i == (l - 1) } }))
                    .SetName(PickTestNameForFilename(actualTestName) + NameSuffix);

                var normalTestPathName = Portability.NormalizeDirectorySeparators(actualTestName);
                var testFileName = Path.GetFileName(normalTestPathName);
                foreach (var part in normalTestPathName.Split(Path.DirectorySeparatorChar))
                {
                    if (part != testFileName)
                    {
                        item.SetCategory(part);
                    }
                }

                if (isIgnored)
                    item.Ignore();

                yield return item;
            }
        }
コード例 #49
0
ファイル: GenericTestFixture.cs プロジェクト: Ocelloid/JSIL
 protected ComparisonTest MakeTest(
     string filename, string[] stubbedAssemblies = null,
     TypeInfoProvider typeInfo = null,
     AssemblyCache assemblyCache = null
 )
 {
     return new ComparisonTest(
         EvaluatorPool,
         filename, stubbedAssemblies,
         typeInfo, assemblyCache
     );
 }
コード例 #50
0
 public DecomposeMutationOperators(TypeSystem typeSystem, TypeInfoProvider typeInfo)
 {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
 }
コード例 #51
0
ファイル: JavascriptAssemblyEmitter.cs プロジェクト: sq/JSIL
 public IAstEmitter MakeAstEmitter (
     JSILIdentifier jsil, TypeSystem typeSystem, TypeInfoProvider typeInfoProvider, Configuration configuration
 ) {
     return new JavascriptAstEmitter(
         Formatter, jsil, typeSystem, typeInfoProvider, configuration
     );
 }
コード例 #52
0
 public SimpleTestCasesForStubbedBcl()
 {
     TypeInfoProvider = MakeDefaultProvider();
 }
コード例 #53
0
ファイル: Util.cs プロジェクト: robashton/JSIL
        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();
            }
        }
コード例 #54
0
ファイル: GenericTestFixture.cs プロジェクト: poizan42/JSIL
        /// <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,
            Func<Configuration> getConfiguration = null
        )
        {
            var started = DateTime.UtcNow.Ticks;

            string commonFile = null;
            for (var i = 0; i < filenames.Length; i++) {
                if (filenames[i].Contains(Path.Combine ("", "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);

                RunComparisonTest(
                    filename, stubbedAssemblies, typeInfo,
                    errorCheckPredicate, failureList,
                    commonFile, shouldRunJs, asmCache,
                    getConfiguration ?? MakeConfiguration
                );
            }

            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()))
            );
        }
コード例 #55
0
ファイル: GenericTestFixture.cs プロジェクト: poizan42/JSIL
        protected IEnumerable<TestCaseData> FolderTestSource(string folderName, TypeInfoProvider typeInfo = null, AssemblyCache asmCache = null)
        {
            var testPath = Path.GetFullPath(Path.Combine(ComparisonTest.TestSourceFolder, folderName));
            var testNames = Directory.GetFiles(testPath, "*.cs")
                .Concat(Directory.GetFiles(testPath, "*.vb"))
                .Concat(Directory.GetFiles(testPath, "*.fs"))
                .OrderBy((s) => s).ToArray();

            string commonFile = null;

            foreach (var testName in testNames) {
                if (Path.GetFileNameWithoutExtension(testName) == "Common") {
                    commonFile = testName;
                    break;
                }
            }

            for (int i = 0, l = testNames.Length; i < l; i++) {
                var testName = testNames[i];
                if (Path.GetFileNameWithoutExtension(testName) == "Common")
                    continue;

                yield return (new TestCaseData(new object[] { new object[] { testName, typeInfo, asmCache, commonFile, i == (l - 1) } }))
                    .SetName(PickTestNameForFilename(testName))
                    .SetDescription(String.Format("{0}\\{1}", folderName, Path.GetFileName(testName)))
                    .SetCategory(folderName);
            }
        }
コード例 #56
0
 public SimpleTestCasesForTranslatedBcl()
 {
     TypeInfoProvider = MakeDefaultProvider();
     AssemblyCache = new AssemblyCache();
 }
コード例 #57
0
ファイル: GenericTestFixture.cs プロジェクト: poizan42/JSIL
        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;
        }
コード例 #58
0
ファイル: GenericTestFixture.cs プロジェクト: cbsistem/JSIL
        private IEnumerable<TestCaseData> FolderTestSource(string folderName, string subfolders, TypeInfoProvider typeInfo, AssemblyCache asmCache)
        {
            if (folderName.StartsWith("exclude_", StringComparison.InvariantCultureIgnoreCase))
            {
                yield break;
            }

            var testPath = Path.GetFullPath(Path.Combine(ComparisonTest.TestSourceFolder, subfolders, folderName));

            if (!Directory.Exists(testPath))
            {
                Console.WriteLine("WARNING: Folder {0} doesn't exist.", testPath);
                yield break;
            }

            subfolders = Path.Combine(subfolders, folderName);

            var testNames = Directory.GetFiles(testPath, "*.cs")
                .Concat(Directory.GetFiles(testPath, "*.vb"))
                .Concat(Directory.GetFiles(testPath, "*.fs"))
                .Concat(Directory.GetFiles(testPath, "*.js"))
                .Concat(Directory.GetFiles(testPath, "*.il"))
                .Concat(Directory.GetFiles(testPath, "*.cpp"))
                .OrderBy((s) => s).ToArray();

            string commonFile = null;

            foreach (var testName in testNames)
            {
                if (Path.GetFileNameWithoutExtension(testName) == "Common")
                {
                    commonFile = testName;
                    break;
                }
            }

            for (int i = 0, l = testNames.Length; i < l; i++)
            {
                var testName = testNames[i];
                if (Path.GetFileNameWithoutExtension(testName) == "Common")
                    continue;

                var item = (new TestCaseData(new object[] {new object[] {testName, typeInfo, asmCache, commonFile, false}}))
                    .SetName(PickTestNameForFilename(testName) + NameSuffix)
                    .SetDescription(String.Format("{0}\\{1}", subfolders, Path.GetFileName(testName)));
                foreach (var category in subfolders.Split(Path.DirectorySeparatorChar))
                {
                    item.SetCategory(category);
                }
                yield return item;
            }

            string[] subdirectoryEntries = Directory.GetDirectories(testPath);
            foreach (string subdirectory in subdirectoryEntries)
                foreach (var item in FolderTestSource(subdirectory.Split(Path.DirectorySeparatorChar).Last(), subfolders, typeInfo, asmCache))
                    yield return item;
        }
コード例 #59
0
ファイル: GenericTestFixture.cs プロジェクト: poizan42/JSIL
        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;
        }
コード例 #60
0
 public SimpleTestCasesForTranslatedBcl()
 {
     TypeInfoProvider = MakeDefaultProvider();
 }