|
| 1 | +module fsdocs.Tests.ConvertCommand |
| 2 | + |
| 3 | +open System.IO |
| 4 | +open fsdocs |
| 5 | +open NUnit.Framework |
| 6 | +open FsUnitTyped |
| 7 | + |
| 8 | +do FSharp.Formatting.TestHelpers.enableLogging () |
| 9 | + |
| 10 | +let (</>) a b = Path.Combine(a, b) |
| 11 | + |
| 12 | +let literateTestFiles = Path.GetFullPath(Path.Combine(__SOURCE_DIRECTORY__, "..", "FSharp.Literate.Tests", "files")) |
| 13 | + |
| 14 | +// -------------------------------------------------------------------------------------- |
| 15 | +// Integration tests for ConvertCommand |
| 16 | +// -------------------------------------------------------------------------------------- |
| 17 | + |
| 18 | +[<Test>] |
| 19 | +let ``ConvertCommand converts .md file to HTML`` () = |
| 20 | + let inputFile = literateTestFiles </> "simple2.md" |
| 21 | + let outputFile = Path.GetTempPath() </> "fsdocs-tool-tests" </> "simple2-convert.html" |
| 22 | + Directory.CreateDirectory(Path.GetDirectoryName(outputFile)) |> ignore |
| 23 | + |
| 24 | + let cmd = ConvertCommand() |
| 25 | + cmd.input <- inputFile |
| 26 | + cmd.output <- outputFile |
| 27 | + cmd.outputFormat <- "html" |
| 28 | + let result = cmd.Execute() |
| 29 | + |
| 30 | + result |> shouldEqual 0 |
| 31 | + File.Exists(outputFile) |> shouldEqual true |
| 32 | + let html = File.ReadAllText(outputFile) |
| 33 | + html |> shouldContainText "Heading" |
| 34 | + html |> shouldContainText "Code sample" |
| 35 | + |
| 36 | +[<Test>] |
| 37 | +let ``ConvertCommand converts .fsx file to HTML`` () = |
| 38 | + let inputFile = literateTestFiles </> "simple1.fsx" |
| 39 | + let outputFile = Path.GetTempPath() </> "fsdocs-tool-tests" </> "simple1-convert.html" |
| 40 | + Directory.CreateDirectory(Path.GetDirectoryName(outputFile)) |> ignore |
| 41 | + |
| 42 | + let cmd = ConvertCommand() |
| 43 | + cmd.input <- inputFile |
| 44 | + cmd.output <- outputFile |
| 45 | + cmd.outputFormat <- "html" |
| 46 | + let result = cmd.Execute() |
| 47 | + |
| 48 | + result |> shouldEqual 0 |
| 49 | + File.Exists(outputFile) |> shouldEqual true |
| 50 | + let html = File.ReadAllText(outputFile) |
| 51 | + html |> shouldContainText "Heading" |
| 52 | + html |> shouldContainText "Code sample" |
| 53 | + |
| 54 | +[<Test>] |
| 55 | +let ``ConvertCommand converts .ipynb file to HTML`` () = |
| 56 | + let inputFile = literateTestFiles </> "simple3.ipynb" |
| 57 | + let outputFile = Path.GetTempPath() </> "fsdocs-tool-tests" </> "simple3-convert.html" |
| 58 | + Directory.CreateDirectory(Path.GetDirectoryName(outputFile)) |> ignore |
| 59 | + |
| 60 | + let cmd = ConvertCommand() |
| 61 | + cmd.input <- inputFile |
| 62 | + cmd.output <- outputFile |
| 63 | + cmd.outputFormat <- "html" |
| 64 | + let result = cmd.Execute() |
| 65 | + |
| 66 | + result |> shouldEqual 0 |
| 67 | + File.Exists(outputFile) |> shouldEqual true |
| 68 | + let html = File.ReadAllText(outputFile) |
| 69 | + html |> shouldContainText "Heading" |
| 70 | + html |> shouldContainText "Code sample" |
| 71 | + |
| 72 | +[<Test>] |
| 73 | +let ``ConvertCommand converts .md file to Markdown output format`` () = |
| 74 | + let inputFile = literateTestFiles </> "simple2.md" |
| 75 | + let outputFile = Path.GetTempPath() </> "fsdocs-tool-tests" </> "simple2-convert.md" |
| 76 | + Directory.CreateDirectory(Path.GetDirectoryName(outputFile)) |> ignore |
| 77 | + |
| 78 | + let cmd = ConvertCommand() |
| 79 | + cmd.input <- inputFile |
| 80 | + cmd.output <- outputFile |
| 81 | + cmd.outputFormat <- "markdown" |
| 82 | + let result = cmd.Execute() |
| 83 | + |
| 84 | + result |> shouldEqual 0 |
| 85 | + File.Exists(outputFile) |> shouldEqual true |
| 86 | + |
| 87 | +[<Test>] |
| 88 | +let ``ConvertCommand infers output format from output file extension`` () = |
| 89 | + let inputFile = literateTestFiles </> "simple2.md" |
| 90 | + let outputFile = Path.GetTempPath() </> "fsdocs-tool-tests" </> "simple2-inferred.md" |
| 91 | + Directory.CreateDirectory(Path.GetDirectoryName(outputFile)) |> ignore |
| 92 | + |
| 93 | + let cmd = ConvertCommand() |
| 94 | + cmd.input <- inputFile |
| 95 | + cmd.output <- outputFile |
| 96 | + // no outputFormat set — should infer "markdown" from .md extension |
| 97 | + let result = cmd.Execute() |
| 98 | + |
| 99 | + result |> shouldEqual 0 |
| 100 | + File.Exists(outputFile) |> shouldEqual true |
| 101 | + |
| 102 | +[<Test>] |
| 103 | +let ``ConvertCommand returns error code for non-existent input file`` () = |
| 104 | + let cmd = ConvertCommand() |
| 105 | + cmd.input <- literateTestFiles </> "does-not-exist.md" |
| 106 | + cmd.output <- Path.GetTempPath() </> "fsdocs-tool-tests" </> "out.html" |
| 107 | + let result = cmd.Execute() |
| 108 | + result |> shouldEqual 1 |
| 109 | + |
| 110 | +[<Test>] |
| 111 | +let ``ConvertCommand returns error code for unsupported file extension`` () = |
| 112 | + let inputFile = literateTestFiles </> "template.html" |
| 113 | + let outputFile = Path.GetTempPath() </> "fsdocs-tool-tests" </> "out.html" |
| 114 | + Directory.CreateDirectory(Path.GetDirectoryName(outputFile)) |> ignore |
| 115 | + |
| 116 | + let cmd = ConvertCommand() |
| 117 | + cmd.input <- inputFile |
| 118 | + cmd.output <- outputFile |
| 119 | + let result = cmd.Execute() |
| 120 | + result |> shouldEqual 1 |
0 commit comments