示例#1
0
        public void TestDoesntExist()
        {
            using var tmpdir = new TemporaryDirectory();
            string outputPath = Path.Join(tmpdir.Path, "Output.cs");

            string programText = @"
/// <code doctest=""true"">
///    var x = 1;
/// </code>
";

            var doctestsAndErrors = Extraction.Extract(
                CSharpSyntaxTree.ParseText(
                    programText));

            Assert.AreEqual(0, doctestsAndErrors.Errors.Count);
            var doctests = doctestsAndErrors.Doctests;

            // Test pre-condition
            Assert.IsFalse(File.Exists(outputPath));

            Process.Report got = Process.Check(doctests, outputPath);

            Assert.AreEqual(Process.Report.DoesntExist, got);
        }
示例#2
0
        public void TestOkNoDoctest()
        {
            using var tmpdir = new TemporaryDirectory();
            string outputPath = Path.Join(tmpdir.Path, "Output.cs");

            var doctestsAndErrors = Extraction.Extract(
                CSharpSyntaxTree.ParseText(
                    "No doctest at all"));

            Assert.AreEqual(0, doctestsAndErrors.Errors.Count);
            var doctests = doctestsAndErrors.Doctests;

            Process.Report got = Process.Check(doctests, outputPath);

            Assert.AreEqual(Process.Report.Ok, got);
        }
示例#3
0
        public void TestShouldntExist()
        {
            using var tmpdir = new TemporaryDirectory();
            string outputPath = Path.Join(tmpdir.Path, "Output.cs");

            var doctestsAndErrors = Extraction.Extract(
                CSharpSyntaxTree.ParseText(
                    "no doctest"));

            Assert.AreEqual(0, doctestsAndErrors.Errors.Count);
            var doctests = doctestsAndErrors.Doctests;

            File.WriteAllText(outputPath, "should not exist");

            Process.Report got = Process.Check(doctests, outputPath);

            Assert.AreEqual(Process.Report.ShouldNotExist, got);
        }
示例#4
0
        public void TestOkDoctest()
        {
            using var tmpdir = new TemporaryDirectory();
            string outputPath = Path.Join(tmpdir.Path, "Output.cs");

            string programText = @"
/// <code doctest=""true"">
///    var x = 1;
/// </code>
";

            var doctestsAndErrors = Extraction.Extract(
                CSharpSyntaxTree.ParseText(
                    programText));

            Assert.AreEqual(0, doctestsAndErrors.Errors.Count);
            var doctests = doctestsAndErrors.Doctests;

            File.WriteAllText(outputPath, @"// This file was automatically generated by doctest-csharp.
// !!! DO NOT EDIT OR APPEND !!!

using NUnit.Framework;

namespace Tests
{
    public class DocTests
    {
        [Test]
        public void AtLine1AndColumn4
        {
            var x = 1;
        }
    }
}

// This file was automatically generated by doctest-csharp.
// !!! DO NOT EDIT OR APPEND !!!
");
            Process.Report got = Process.Check(doctests, outputPath);

            Assert.AreEqual(Process.Report.Ok, got);
        }
示例#5
0
        public void TestDifferent()
        {
            using var tmpdir = new TemporaryDirectory();
            string outputPath = Path.Join(tmpdir.Path, "Output.cs");

            string programText       = @"
/// <code doctest=""true"">
///    var x = 1;
/// </code>
";
            var    doctestsAndErrors = Extraction.Extract(
                CSharpSyntaxTree.ParseText(
                    programText));

            Assert.AreEqual(0, doctestsAndErrors.Errors.Count);
            var doctests = doctestsAndErrors.Doctests;

            File.WriteAllText(outputPath, "different content");

            Process.Report got = Process.Check(doctests, outputPath);

            Assert.AreEqual(Process.Report.Different, got);
        }