internal static void TestExecuteSourcesNoInput(string[] sources, string baseline, string testname, ExecuteMethod method)
        {
            LOLCodeCodeProvider provider    = new LOLCodeCodeProvider();
            string             assemblyName = String.Format("{0}.exe", testname);
            CompilerParameters cparam       = GetDefaultCompilerParams(assemblyName, method);

            // Compile test
            CompilerResults results = provider.CompileAssemblyFromSourceBatch(cparam, sources);

            // Collect errors (if any)
            StringBuilder errors = new StringBuilder();

            if (results.Errors.HasErrors)
            {
                for (int i = 0; i < results.Errors.Count; i++)
                {
                    errors.AppendLine(results.Errors[i].ToString());
                }
            }

            // Ensure there are no errors before trying to execute
            Assert.AreEqual(0, results.Errors.Count, errors.ToString());

            if (method == ExecuteMethod.InMemory)
            {
                throw new NotImplementedException("In memory execution is not implimented yet");
            }
            else
            {
                // Run the executeable (collecting it's output) compare to baseline
                Assert.AreEqual(baseline, RunExecuteable(assemblyName));
                File.Delete(assemblyName);
            }
        }
Beispiel #2
0
        static int Main(string[] args)
        {
            LolCompilerArguments arguments = new LolCompilerArguments();

            if (!CommandLine.Parser.ParseArgumentsWithUsage(args, arguments))
            {
                return(2);
            }

            // Ensure some goodness in the arguments
            if (!LolCompilerArguments.PostValidateArguments(arguments))
            {
                // Errors are output by PostValidateArguments to STDERR
                return(3);
            }

            // Warn the user if there is more than one source file, as they will be ignored (for now)
            // TODO: Should be removed eventually
            if (arguments.sources.Length > 1)
            {
                Console.Error.WriteLine("lolc warning: More than one source file specifed. Only '{0}' will be compiled.", arguments.sources[0]);
            }

            // Good to go
            string outfileFile           = String.IsNullOrEmpty(arguments.output) ? Path.ChangeExtension(arguments.sources[0], ".exe") : arguments.output;
            LOLCodeCodeProvider compiler = new LOLCodeCodeProvider();
            CompilerParameters  cparam   = new CompilerParameters();

            cparam.GenerateExecutable      = true;
            cparam.GenerateInMemory        = false;
            cparam.OutputAssembly          = outfileFile;
            cparam.MainClass               = "Program";
            cparam.IncludeDebugInformation = arguments.debug;
            cparam.ReferencedAssemblies.AddRange(arguments.references);
            CompilerResults results = compiler.CompileAssemblyFromFile(cparam, arguments.sources[0]);

            for (int i = 0; i < results.Errors.Count; i++)
            {
                Console.Error.WriteLine(results.Errors[i].ToString());
            }

            if (results.Errors.HasErrors)
            {
                Console.Out.WriteLine("Failed to compile.");
                return(1);
            }
            else
            {
                Console.Out.WriteLine("Successfully compiled.");
                return(0);
            }
        }