Esempio n. 1
0
        internal void CompareTrees(IEnumerable <string> sources, IEnumerable <string> fileNames, IEnumerable <ErrorCode> errors, [CallerMemberName] string testName = "")
        {
            Errors.Clear();

            var    file         = path + testName;
            var    compilerArgs = CompilerArguments.Parse(fileNames.Select(n => Path.Combine("$" + testName, n)).Union(new[] { string.Format("/out:{0}.exe", testName) }).ToArray());
            var    parser       = ProjectParser.ParseAll(assembly, compilerArgs, sources.ToArray(), false);
            string result       = parser.ToString();

            string expected = "";

#if REWRITE
            System.IO.File.WriteAllText(file, result);
            expected = result;
#else
            try
            {
                expected = System.IO.File.ReadAllText(file);
            }
            catch { }
#endif
            var foundErrors    = Errors.Reported.Select(e => e.ErrorCode).ToHashSet();
            var expectedErrors = errors.ToHashSet();


            Assert.IsTrue(foundErrors.SetEquals(expectedErrors), "Errors: \r\n" + String.Join("\r\n", Errors.Reported));
            Assert.AreEqual(expected, result);
        }
        private static int Compile(params string[] args)
        {
            Errors.Clear();

            var compilerArgs = CompilerArguments.Parse(args);

            if (compilerArgs.HasErrors)
            {
                return(FailCompilation());
            }

            AssemblyRegistry.Create(compilerArgs.References);
            var assembly = new AssemblyEmitter(compilerArgs);

            ProjectParser.ParseAll(assembly, compilerArgs, true);

            if (Errors.Reported.Count > 0)
            {
                return(FailCompilation());
            }

            if (!assembly.Save())
            {
                return(FailCompilation());
            }

            return(0);
        }