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()); }
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()); }
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()); }
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()); }