Exemple #1
0
        private static DMTestFlags GetDMTestFlags(string sourceFile)
        {
            DMTestFlags testFlags = DMTestFlags.NoError;

            using (StreamReader reader = new StreamReader(sourceFile)) {
                string firstLine = reader.ReadLine();

                if (firstLine.Contains("IGNORE", StringComparison.InvariantCulture))
                {
                    testFlags |= DMTestFlags.Ignore;
                }
                if (firstLine.Contains("COMPILE ERROR", StringComparison.InvariantCulture))
                {
                    testFlags |= DMTestFlags.CompileError;
                }
                if (firstLine.Contains("RUNTIME ERROR", StringComparison.InvariantCulture))
                {
                    testFlags |= DMTestFlags.RuntimeError;
                }
                if (firstLine.Contains("RETURN TRUE", StringComparison.InvariantCulture))
                {
                    testFlags |= DMTestFlags.ReturnTrue;
                }
            }

            return(testFlags);
        }
Exemple #2
0
        public void TestFiles(string sourceFile, DMTestFlags testFlags)
        {
            string compiledFile = Compile(sourceFile);

            if (testFlags.HasFlag(DMTestFlags.CompileError))
            {
                Assert.IsNull(compiledFile, $"Expected an error during DM compilation");
                Cleanup(compiledFile);
                return;
            }

            Assert.IsTrue(compiledFile is not null && File.Exists(compiledFile), $"Failed to compile DM source file");
            Assert.IsTrue(_dreamMan.LoadJson(compiledFile), $"Failed to load {compiledFile}");

            (bool successfulRun, DreamValue returned) = RunTest();
            if (testFlags.HasFlag(DMTestFlags.RuntimeError))
            {
                Assert.IsFalse(successfulRun, "A DM runtime exception was expected");
            }
            else
            {
                //TODO: This should use the runtime exception as the failure message
                Assert.IsTrue(successfulRun, "A DM runtime exception was thrown");
            }

            if (testFlags.HasFlag(DMTestFlags.ReturnTrue))
            {
                returned.TryGetValueAsInteger(out int returnInt);
                Assert.IsTrue(returnInt != 0, "Test was expected to return TRUE");
            }

            Cleanup(compiledFile);
        }
Exemple #3
0
        private static IEnumerable <object[]> GetTests()
        {
            Directory.SetCurrentDirectory(TestProject);

            foreach (string sourceFile in Directory.GetFiles("Tests", "*.dm", SearchOption.AllDirectories))
            {
                DMTestFlags testFlags = GetDMTestFlags(sourceFile);
                if (testFlags.HasFlag(DMTestFlags.Ignore))
                {
                    continue;
                }

                yield return(new object[] {
                    Path.GetFullPath(sourceFile),
                    testFlags
                });
            }
        }