예제 #1
0
        public void TestSingleInput()
        {
            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)
        {
            // SoDead();
            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:24: a line ends with `;`{nl}",
                consoleCapture.Output());
        }
예제 #2
0
        public void TestRemove()
        {
            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)
        {
            // SoDead();
            System.Console.WriteLine(""Hello, World!"");
        }
    }
}";

            using var consoleCapture = new ConsoleCapture();

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

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

            var newProgramText = System.IO.File.ReadAllText(path);

            var expected =
                @"
namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Console.WriteLine(""Hello, World!"");
        }
    }
}";
            string nl = Environment.NewLine;

            Assert.AreEqual(0, exitCode);
            Assert.AreEqual(expected, newProgramText);
            Assert.AreEqual(
                $"FIXED {path}{nl}",
                consoleCapture.Output());
        }
예제 #3
0
        public void TestWithNonCodeInput()
        {
            using var tmpdir = new TemporaryDirectory();

            using var consoleCapture = new ConsoleCapture();

            string path = System.IO.Path.Join(tmpdir.Path, "SomeProgram.cs");

            System.IO.File.WriteAllText(path, "this is not parsable C# code.");

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

            string nl = Environment.NewLine;

            Assert.AreEqual(0, exitCode);
            Assert.AreEqual($"OK   {path}{nl}", consoleCapture.Output());
        }
예제 #4
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());
        }