/src/test/Fake.Core.UnitTests/Fake.DotNet.Cli.fs

https://github.com/fsharp/FAKE · F# · 145 lines · 115 code · 30 blank · 0 comment · 0 complexity · a516394915cd159cb52f4f0ba4538a14 MD5 · raw file

  1. module Fake.DotNet.CliTests
  2. open Fake.Core
  3. open Fake.DotNet
  4. open Expecto
  5. [<Tests>]
  6. let tests =
  7. testList "Fake.DotNet.Cli.Tests" [
  8. testCase "Test that we can use Process-Helpers on Cli Paramters" <| fun _ ->
  9. let cli =
  10. DotNet.Options.Create()
  11. |> Process.setEnvironmentVariable "Somevar" "someval"
  12. Expect.equal cli.Environment.["Somevar"] "someval" "Retrieving the correct environment variable failed."
  13. testCase "Test that the default dotnet nuget push arguments returns empty string" <| fun _ ->
  14. let cli =
  15. DotNet.NuGetPushOptions.Create().PushParams
  16. |> DotNet.buildNugetPushArgs
  17. |> Args.toWindowsCommandLine
  18. Expect.isEmpty cli "Empty push args."
  19. testCase "Test that the dotnet nuget push arguments with all params setreturns correct string" <| fun _ ->
  20. let param =
  21. { DotNet.NuGetPushOptions.Create().PushParams with
  22. DisableBuffering = true
  23. ApiKey = Some "abc123"
  24. NoSymbols = true
  25. NoServiceEndpoint = true
  26. Source = Some "MyNuGetSource"
  27. SymbolApiKey = Some "MySymbolApiKey"
  28. SymbolSource = Some "MySymbolSource"
  29. Timeout = Some <| System.TimeSpan.FromMinutes 5.0
  30. PushTrials = 5 }
  31. let cli =
  32. param
  33. |> DotNet.buildNugetPushArgs
  34. |> Args.toWindowsCommandLine
  35. let expected = "--disable-buffering --api-key abc123 --no-symbols --no-service-endpoint --source MyNuGetSource --symbol-api-key MySymbolApiKey --symbol-source MySymbolSource --timeout 300"
  36. Expect.equal cli expected "Push args generated correctly."
  37. testCase "Test that the dotnet publish self-contained works as expected" <| fun _ ->
  38. let param =
  39. { DotNet.PublishOptions.Create() with
  40. SelfContained = Some false }
  41. let cli =
  42. param
  43. |> DotNet.buildPublishArgs
  44. |> Args.toWindowsCommandLine
  45. let expected = "--configuration Release --self-contained=false"
  46. Expect.equal cli expected "Push args generated correctly."
  47. testCase "Test that the dotnet publish force works as expected" <| fun _ ->
  48. let param =
  49. { DotNet.PublishOptions.Create() with
  50. Force = Some true }
  51. let cli =
  52. param
  53. |> DotNet.buildPublishArgs
  54. |> Args.toWindowsCommandLine
  55. let expected = "--configuration Release --force"
  56. Expect.equal cli expected "Push args generated correctly."
  57. testCase "Test that the dotnet publish manifest works as expected" <| fun _ ->
  58. let param =
  59. { DotNet.PublishOptions.Create() with
  60. Manifest = Some ["Path1"; "Path2"] }
  61. let cli =
  62. param
  63. |> DotNet.buildPublishArgs
  64. |> Args.toWindowsCommandLine
  65. let expected = "--configuration Release --manifest Path1 --manifest Path2"
  66. Expect.equal cli expected "Push args generated correctly."
  67. testCase "Test that the dotnet new command works as expected" <| fun _ ->
  68. let param =
  69. { DotNet.NewOptions.Create() with
  70. DryRun = true
  71. Force = true
  72. Language = DotNet.NewLanguage.FSharp
  73. Name = Some("my-awesome-project")
  74. NoUpdateCheck = true
  75. Output = Some("/path/to/code") }
  76. let cli =
  77. param
  78. |> DotNet.buildNewArgs
  79. |> Args.toWindowsCommandLine
  80. let expected = "--dry-run --force --language F# --name my-awesome-project --no-update-check --output /path/to/code"
  81. Expect.equal cli expected "New args generated correctly."
  82. testCase "Test that the dotnet new command works as expected with spaces in arguments" <| fun _ ->
  83. let param =
  84. { DotNet.NewOptions.Create() with
  85. DryRun = true
  86. Force = true
  87. Language = DotNet.NewLanguage.FSharp
  88. Name = Some("my awesome project")
  89. NoUpdateCheck = true
  90. Output = Some("/path to/code") }
  91. let cli =
  92. param
  93. |> DotNet.buildNewArgs
  94. |> Args.toWindowsCommandLine
  95. let expected = "--dry-run --force --language F# --name \"my awesome project\" --no-update-check --output \"/path to/code\""
  96. Expect.equal cli expected "New args generated correctly."
  97. testCase "Test that the dotnet new --install command works as expected" <| fun _ ->
  98. let param =
  99. { DotNet.TemplateInstallOptions.Create("my-awesome-template") with
  100. NugetSource = Some("C:\\path\\to\\tool") }
  101. let cli =
  102. param
  103. |> DotNet.buildTemplateInstallArgs
  104. |> Args.toWindowsCommandLine
  105. let expected = "--install my-awesome-template --nuget-source \"C:\\path\\to\\tool\""
  106. Expect.equal cli expected "New --install args generated correctly."
  107. testCase "Test that the dotnet new --uninstall command works as expected" <| fun _ ->
  108. let param = DotNet.TemplateUninstallOptions.Create("my-awesome-template")
  109. let cli =
  110. param
  111. |> DotNet.buildTemplateUninstallArgs
  112. |> Args.toWindowsCommandLine
  113. let expected = "--uninstall my-awesome-template"
  114. Expect.equal cli expected "New --uninstall args generated correctly."
  115. ]