|
| 1 | +namespace XakeLibTests |
| 2 | + |
| 3 | +open System.IO |
| 4 | +open NUnit.Framework |
| 5 | + |
| 6 | +open Xake |
| 7 | + |
| 8 | +[<TestFixture (Description = "Command line tests")>] |
| 9 | +type CommandLineTests() = |
| 10 | + |
| 11 | + let currentDir = Path.Combine (__SOURCE_DIRECTORY__, "..") |
| 12 | + |
| 13 | + [<Test (Description = "Verifies reading common switches")>] |
| 14 | + member test.AcceptKnownSwitches() = |
| 15 | + |
| 16 | + let scriptOptions = ref XakeOptions |
| 17 | + let args = |
| 18 | + ["/t"; "33"; "/R"; currentDir; "/LL"; "Loud"; |
| 19 | + "/FL"; "aaaaa"; "/D"; "AA=BBB"; "/D"; "AA1=CCC"; "/FLL"; "Silent"] |
| 20 | + |
| 21 | + do xakeArgs args XakeOptions { |
| 22 | + wantOverride (["test"]) |
| 23 | + |
| 24 | + rules [ |
| 25 | + "test" => action { |
| 26 | + let! opts = getCtxOptions() |
| 27 | + scriptOptions := opts |
| 28 | + } |
| 29 | + ] |
| 30 | + } |
| 31 | + |
| 32 | + let finalOptions = !scriptOptions |
| 33 | + Assert.AreEqual(33, finalOptions.Threads) |
| 34 | + Assert.AreEqual(currentDir, finalOptions.ProjectRoot) |
| 35 | + Assert.AreEqual("aaaaa", finalOptions.FileLog) |
| 36 | + Assert.AreEqual(Verbosity.Silent, finalOptions.FileLogLevel) |
| 37 | + Assert.AreEqual(Verbosity.Loud, finalOptions.ConLogLevel) |
| 38 | + Assert.AreEqual([("AA", "BBB"); ("AA1", "CCC")], finalOptions.Vars) |
| 39 | + |
| 40 | + [<Test (Description = "Verifies reading target list")>] |
| 41 | + member test.ReadsTargets() = |
| 42 | + |
| 43 | + let scriptOptions = ref XakeOptions |
| 44 | + let executed2 = ref false |
| 45 | + let args = ["/t"; "31"; "target1"; "target2"] |
| 46 | + |
| 47 | + do xakeArgs args XakeOptions { |
| 48 | + |
| 49 | + rules [ |
| 50 | + "target1" => action { |
| 51 | + let! opts = getCtxOptions() |
| 52 | + scriptOptions := opts |
| 53 | + } |
| 54 | + "target2" => action { |
| 55 | + executed2 := true |
| 56 | + } |
| 57 | + ] |
| 58 | + } |
| 59 | + |
| 60 | + let finalOptions = !scriptOptions |
| 61 | + Assert.AreEqual(31, finalOptions.Threads) |
| 62 | + Assert.AreEqual(["target1"; "target2"], finalOptions.Targets) |
| 63 | + Assert.IsTrue !executed2 |
| 64 | + |
| 65 | + |
| 66 | + [<Test (Description = "Verifies reading incorrect"); Ignore>] |
| 67 | + member test.WarnsOnIncorrectSwitch() = |
| 68 | + |
| 69 | + do xakeArgs ["/xxx"] XakeOptions { |
| 70 | + want ["ss"] |
| 71 | + } |
| 72 | + |
| 73 | + //raise <| new System.NotImplementedException() |
| 74 | + |
| 75 | + [<Test (Description = "Verifies that command line is ignored when Ignore option is set")>] |
| 76 | + member test.IgnoresCommandLine() = |
| 77 | + |
| 78 | + let scriptOptions = ref XakeOptions |
| 79 | + let args = |
| 80 | + ["/t"; "33"; "/R"; currentDir; "/LL"; "Loud"; |
| 81 | + "/FL"; "aaaaa"; "target"] |
| 82 | + |
| 83 | + do xakeArgs args {XakeOptions with IgnoreCommandLine = true; Threads = 2; FileLog = "ss"; Targets = ["main"]} { |
| 84 | + rules [ |
| 85 | + "main" => action { |
| 86 | + let! opts = getCtxOptions() |
| 87 | + scriptOptions := opts |
| 88 | + } |
| 89 | + ] |
| 90 | + } |
| 91 | + |
| 92 | + let finalOptions = !scriptOptions |
| 93 | + Assert.AreEqual(2, finalOptions.Threads) |
| 94 | + Assert.AreEqual("ss", finalOptions.FileLog) |
| 95 | + Assert.AreEqual(["main"], finalOptions.Targets) |
0 commit comments