示例#1
0
        public static bool Compile(TestCase tc)
        {
            tc.CopySourceFiles();

            var lang = tc.Language;

            if (lang == CompilerLanguage.CIL)
            {
                return(ILAsm.Run(tc));
            }

            using (tc.Root.ChangeCurrentDirectory())
            {
                var options = new CompilerOptions();
                try
                {
                    ResolveReferences(tc.Root, tc.References, options.References);
                }
                catch (Exception exc)
                {
                    tc.Error = String.Format("Unable to resolve test case {0} references. Exception:\n{1}",
                                             tc.Name, exc);
                    return(false);
                }

                SetCompilerOptions(tc, lang, options);

                try
                {
                    string cout = CompilerConsole.Run(options, true);
                    if (CompilerConsole.HasErrors(cout))
                    {
                        tc.Error = String.Format("Unable to compile test case {0}.\n{1}", tc.Name, cout);
                        return(false);
                    }
                }
                catch (Exception exc)
                {
                    tc.Error = String.Format("Unable to compile test case {0}. Exception:\n{1}", tc.Name, exc);
                    return(false);
                }
            }

            return(true);
        }
示例#2
0
        static void RunTest(Test test)
        {
            string wd = Environment.CurrentDirectory;

            const string prefix   = "__pfx_nunit";
            const string name_cs  = prefix + ".cs";
            const string name_exe = prefix + ".exe";
            const string name_swf = prefix + ".swf";

            string mainFile = Path.Combine(wd, name_cs);

            File.WriteAllText(mainFile, test.MainCode);

            var compilerOptions = new CompilerOptions
            {
                Target   = CompilerTarget.ConsoleApp,
                Output   = name_exe,
                NoLogo   = true,
                NoConfig = true,
                NoStdlib = true
            };

            GlobalSettings.AddCommonReferences(compilerOptions);
            compilerOptions.AddRef(_asmpath);
            compilerOptions.Input.Add(name_cs);

            string cout = CompilerConsole.Run(compilerOptions);

            if (CompilerConsole.HasErrors(cout))
            {
                Console.WriteLine(cout);
                Environment.Exit(-1);
            }

            string path_exe = Path.Combine(wd, name_exe);
            string path_swf = Path.Combine(wd, name_swf);

            var asm = LoadAssembly(path_exe);

            MakeSwf(asm, path_swf);
            RunPlayer(test, path_swf);
            Report.AddTest(test);
        }
示例#3
0
        static bool GenerateApp(TestCase test, TestDriverSettings tds)
        {
            test.VM         = VM.AVM;
            test.OutputPath = Path.Combine(test.Root, "test." + tds.OutputExtension);

            if (tds.IsJavaScript)
            {
                try
                {
                    var compiler = new JsCompiler(new FileInfo(test.ExePath));
                    compiler.Compile(new FileInfo(test.OutputPath));
                    return(true);
                }
                catch (Exception e)
                {
                    test.Error = string.Format("Unable to generate {0} file.\nException: {1}", tds.OutputFormat, e);
                    return(false);
                }
            }

            bool refl = test.FullName.Contains("Reflection");

            GlobalSettings.ReflectionSupport = refl;

            if (test.UsePfc)
            {
                var options = new PfxCompilerOptions
                {
                    Nologo     = true,
                    Input      = test.ExePath,
                    Output     = test.OutputPath,
                    Reflection = refl
                };
                string err = PfxCompiler.Run(options);
                if (CompilerConsole.HasErrors(err))
                {
                    throw new InvalidOperationException("Unable to compile " + test.Name + ".\n" + err);
                }
            }
            else
            {
                IAssembly asm;
                if (!LoadAssembly(test, tds, out asm))
                {
                    return(false);
                }

                try
                {
                    string cl = string.Format("/format:{0}", tds.OutputFormat);

                    if (tds.IsSWF)
                    {
                        cl += " /framesize:100 /fp:10 /nohtml /exception-break";
                    }

                    FlashLanguageInfrastructure.Serialize(asm, test.OutputPath, cl);
                }
                catch (Exception e)
                {
                    test.Error = string.Format("Unable to generate {0} file.\nException: {1}", tds.OutputFormat, e);
                    return(false);
                }
            }

            return(true);
        }