Пример #1
0
        private static int Compile(string Namespace, string SourceFileName, string ErrorFileName, string OutputRootFolder, bool ActivateVerification, Guid singledGuid, string singledName)
        {
            Compiler c = new Compiler();

            c.Compile(SourceFileName);
            IErrorList ErrorList = c.ErrorList;

            if (ErrorList.IsEmpty)
            {
                TargetCSharp t = new TargetCSharp(c, Namespace);
                t.OutputRootFolder = OutputRootFolder;
                t.SingledGuid      = singledGuid;
                t.SingledName      = singledName;
                t.SourceFileName   = SourceFileName;
                t.Translate();

                ErrorList = t.ErrorList;
            }

            Debug.WriteLine(ErrorList.ToString());

            if (!ErrorList.IsEmpty)
            {
                ReportErrors(ErrorFileName, ErrorList);
                return(-2);
            }

            return(0);
        }
        public static void TestCompilationCalls()
        {
            Compiler Compiler = new Compiler();

            Assert.That(Compiler != null, "Sanity Check #0");

            string TestFileName = $"{RootPath}/coverage/coverage.easly";

            Exception ex;
            string    NullString = null;

            ex = Assert.Throws <ArgumentNullException>(() => Compiler.Compile(NullString));
            Assert.That(ex.Message == $"Value cannot be null.{NL}Parameter name: fileName", ex.Message);

            Compiler.Compile("notfound.easly");
            Assert.That(!Compiler.ErrorList.IsEmpty && Compiler.ErrorList.At(0) is IErrorInputFileNotFound AsInputFileNotFound && AsInputFileNotFound.Message == "File not found: 'notfound.easly'.", ErrorListToString(Compiler));

            using (FileStream fs = new FileStream(TestFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
            {
                Compiler.Compile(TestFileName);
                Assert.That(!Compiler.ErrorList.IsEmpty && Compiler.ErrorList.At(0) is IErrorInputFileInvalid, ErrorListToString(Compiler));
            }

            Stream NullStream = null;

            ex = Assert.Throws <ArgumentNullException>(() => Compiler.Compile(NullStream));
            Assert.That(ex.Message == $"Value cannot be null.{NL}Parameter name: stream", ex.Message);

            Compiler.Compile(TestFileName);
            Assert.That(Compiler.ErrorList.IsEmpty, ErrorListToString(Compiler));

            string InvalidFile = File.Exists($"{RootPath}Test-Easly-Compiler.dll") ? $"{RootPath}Test-Easly-Compiler.dll" : $"{RootPath}Test-Easly-Compiler.csproj";

            using (FileStream fs = new FileStream(InvalidFile, FileMode.Open, FileAccess.Read))
            {
                Compiler.Compile(fs);
                Assert.That(!Compiler.ErrorList.IsEmpty && Compiler.ErrorList.At(0) is IErrorInputFileInvalid, ErrorListToString(Compiler));
            }

            IRoot NullRoot = null;

            ex = Assert.Throws <ArgumentNullException>(() => Compiler.Compile(NullRoot));
            Assert.That(ex.Message == $"Value cannot be null.{NL}Parameter name: root", ex.Message);

            using (FileStream fs = new FileStream(TestFileName, FileMode.Open, FileAccess.Read))
            {
                Compiler.Compile(fs);
                Assert.That(Compiler.ErrorList.IsEmpty, ErrorListToString(Compiler));
            }

            IRoot ClonedRoot = NodeHelper.DeepCloneNode(CoverageNode, cloneCommentGuid: true) as IRoot;

            NodeTreeHelper.SetGuidProperty(ClonedRoot.ClassBlocks.NodeBlockList[0].NodeList[0], nameof(IClass.ClassGuid), Guid.Empty);
            Assert.That(!NodeTreeDiagnostic.IsValid(ClonedRoot, assertValid: false));

            Compiler.Compile(ClonedRoot);
            Assert.That(!Compiler.ErrorList.IsEmpty && Compiler.ErrorList.At(0) is IErrorInputRootInvalid, ErrorListToString(Compiler));

            Compiler.ActivateVerification = false;

            Compiler.InferenceRetries = -1;
            Compiler.Compile(CoverageNode as IRoot);
            Assert.That(!Compiler.ErrorList.IsEmpty && Compiler.ErrorList.At(0) is IErrorInternal, ErrorListToString(Compiler));

            Compiler.InferenceRetries = 20;

            //Debug.Assert(false);
            Compiler.Compile(CoverageNode as IRoot);
            Assert.That(Compiler.ErrorList.IsEmpty, ErrorListToString(Compiler));

            Assert.That(Compiler.ActivateVerification == false);

            TargetCSharp t = new TargetCSharp(Compiler, "Test");

            t.OutputRootFolder = "./bin/Output";
            t.Translate();

            Assert.That(t.ErrorList.IsEmpty, ErrorListToString(Compiler));
        }