示例#1
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);
        }
示例#2
0
        public void TestReportToFile()
        {
            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}");

            string reportPath = Path.Join(tmpdir.Path, "report.json");

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

            string expectedReport = $@"[
  {{
    ""path"": ""{path.Replace(@"\", @"\\")}"",
    ""records"": [
      {{
        ""prefix"": ""TODO"",
        ""suffix"": "" (mristin, 2020-07-20): Do something!"",
        ""line"": 0,
        ""column"": 0,
        ""status"": ""ok""
      }}
    ]
  }}
]
";

            Assert.AreEqual("", consoleCapture.Error());
            Assert.AreEqual("", consoleCapture.Output());
            Assert.IsTrue(File.Exists(reportPath));
            Assert.AreEqual(expectedReport, File.ReadAllText(reportPath));
            Assert.AreEqual(0, exitCode);
        }
示例#3
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);
        }