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

            using var consoleCapture = new ConsoleCapture();

            string nl = Environment.NewLine;

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

            File.WriteAllText(path, $"// TODO (mristin, 2020-07-20): Do something!{nl}");

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

            Assert.AreEqual("", consoleCapture.Error());
            Assert.AreEqual(
                $@"[
  {{
    ""path"": ""{path.Replace(@"\", @"\\")}"",
    ""records"": [
      {{
        ""prefix"": ""TODO"",
        ""suffix"": "" (mristin, 2020-07-20): Do something!"",
        ""line"": 0,
        ""column"": 0,
        ""status"": ""ok""
      }}
    ]
  }}
]
",
                consoleCapture.Output());
            Assert.AreEqual(0, exitCode);
        }
Exemplo n.º 2
0
        public void TestWithInvalidAndValidTodoAndVerbose()
        {
            using var tmpdir = new TemporaryDirectory();

            using var consoleCapture = new ConsoleCapture();

            string nl = Environment.NewLine;

            string pathNotOk = Path.Join(tmpdir.Path, "NotOk.cs");

            File.WriteAllText(pathNotOk, $"// TODO (mristin): Do something!{nl}");

            string pathOk = Path.Join(tmpdir.Path, "Ok.cs");

            File.WriteAllText(pathOk, "// TODO (mristin, 2020-07-20): Do something else!");

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

            Assert.AreEqual(
                $"FAILED: {pathNotOk}{nl}" +
                $" * Line 1, column 1: invalid suffix (see --suffixes):  (mristin): Do something!{nl}" +
                $"One or more TODOs were invalid. Please see above.{nl}" +
                $"--prefixes was set to: ^TODO ^BUG ^HACK{nl}" +
                $"--disallowed-prefixes was set to: ^DONT-CHECK-IN ^Todo ^todo ^ToDo ^Bug ^bug ^Hack ^hack{nl}" +
                @"--suffixes was set to: ^ \([^)]+, [0-9]{4}-[0-9]{2}-[0-9]{2}\): ." + nl,
                consoleCapture.Error());
            Assert.AreEqual($"OK, 1 todo(s): {pathOk}{nl}", consoleCapture.Output());
            Assert.AreEqual(1, exitCode);
        }
Exemplo n.º 3
0
        public void TestWithNonCodeInput()
        {
            using var tmpdir = new TemporaryDirectory();

            using var consoleCapture = new ConsoleCapture();

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

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

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

            Assert.AreEqual("", consoleCapture.Error());
            Assert.AreEqual("", consoleCapture.Output());
            Assert.AreEqual(0, exitCode);
        }
Exemplo n.º 4
0
        public void TestWithValidTodoAndCaseInsensitive()
        {
            using var tmpdir = new TemporaryDirectory();

            using var consoleCapture = new ConsoleCapture();

            string nl = Environment.NewLine;

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

            File.WriteAllText(path, $"// todo (mristin, 2020-07-20): Do something!{nl}");

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

            Assert.AreEqual("", consoleCapture.Error());
            Assert.AreEqual($"{path}:1:1:todo (mristin, 2020-07-20): Do something!{nl}",
                            consoleCapture.Output());
            Assert.AreEqual(0, exitCode);
        }
Exemplo n.º 5
0
        public void TestExclude()
        {
            using var tmpdir = new TemporaryDirectory();

            using var consoleCapture = new ConsoleCapture();

            string nl = Environment.NewLine;

            string pathNotOkButExcluded = Path.Join(tmpdir.Path, "NotOk.cs");

            File.WriteAllText(pathNotOkButExcluded, $"// TODO (mristin): Do something, but excluded!{nl}");

            string pathOk = Path.Join(tmpdir.Path, "Ok.cs");

            File.WriteAllText(pathOk, "// TODO (mristin, 2020-07-20): Do something else!");

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

            Assert.AreEqual("", consoleCapture.Error());
            Assert.AreEqual($"{pathOk}:1:1:TODO (mristin, 2020-07-20): Do something else!{nl}",
                            consoleCapture.Output());
            Assert.AreEqual(0, exitCode);
        }