Exemplo n.º 1
0
        public void TestExcludes()
        {
            using var tmpdir = new TemporaryDirectory();

            const string programText =
                @"
namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            // SoDead();
            System.Console.WriteLine(""Hello, World!"");
        }
    }
}";
            string includedPath = System.IO.Path.Join(tmpdir.Path, "SomeProgram.cs");
            string excludedPath = System.IO.Path.Join(tmpdir.Path, "ExcludedProgram.cs");

            using var consoleCapture = new ConsoleCapture();

            System.IO.File.WriteAllText(includedPath, programText);
            System.IO.File.WriteAllText(excludedPath, programText);

            int exitCode = Program.MainWithCode(
                new[]
            {
                "--inputs", System.IO.Path.Join(tmpdir.Path, "*.cs"),
                "--excludes", System.IO.Path.Join(tmpdir.Path, "Excluded*.cs"),
            });

            string nl = Environment.NewLine;

            Assert.AreEqual(1, exitCode);
            Assert.AreEqual(
                $"FAIL {includedPath}:{nl}" +
                $"  * Comment starting at 8:13:{nl}" +
                $"    * Cue at 8:24: a line ends with `;`{nl}",
                consoleCapture.Output());
        }
Exemplo n.º 2
0
        public void TestMatchedPatternsReported()
        {
            using var tmpdir = new TemporaryDirectory();

            string       path        = System.IO.Path.Join(tmpdir.Path, "SomeProgram.cs");
            const string programText =
                @"
namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            // if(isDead)
            System.Console.WriteLine(""Hello, World!"");
        }
    }
}";

            using var consoleCapture = new ConsoleCapture();

            System.IO.File.WriteAllText(path, programText);

            int exitCode = Program.MainWithCode(new[] { "--inputs", path });

            string nl = Environment.NewLine;

            Assert.AreEqual(1, exitCode);
            Assert.AreEqual(
                $"FAIL {path}:{nl}" +
                $"  * Comment starting at 8:13:{nl}" +
                $"    * Cue at 8:16: a line matches the pattern \"control statement\"{nl}" +
                $"The matched patterns were:{nl}" +
                $@"  * ""control statement"": ^\s*(if|else\s+if|for|foreach|switch|while)\s*\(.*\)\s*${nl}",
                consoleCapture.Output());
        }