|
| 1 | +module ``Copy task`` |
| 2 | + |
| 3 | +open NUnit.Framework |
| 4 | + |
| 5 | +open Xake |
| 6 | +open Xake.Tasks |
| 7 | + |
| 8 | +open System.IO |
| 9 | + |
| 10 | +let TestOptions = {ExecOptions.Default with Threads = 1; Targets = ["main"]; ConLogLevel = Diag; FileLogLevel = Silent} |
| 11 | + |
| 12 | +[<Test>] |
| 13 | +let ``copies single file``() = |
| 14 | + "." </> ".xake" |> File.Delete |
| 15 | + if Directory.Exists "cptgt" then |
| 16 | + Directory.Delete ("cptgt", true) |
| 17 | + |
| 18 | + do xake TestOptions { |
| 19 | + rules [ |
| 20 | + "main" => action { |
| 21 | + do! need ["samplefile"] |
| 22 | + do! Cp {CpArgs.Default with file = "samplefile"; todir = "cptgt"} |
| 23 | + } |
| 24 | + |
| 25 | + "samplefile" ..> writeText "hello world" |
| 26 | + ] |
| 27 | + } |
| 28 | + |
| 29 | + Assert.True <| File.Exists ("cptgt" </> "samplefile") |
| 30 | + |
| 31 | +[<Test>] |
| 32 | +let ``copies folder flatten``() = |
| 33 | + "." </> ".xake" |> File.Delete |
| 34 | + ["cptgt"; "cpin"] |> List.map (fun d -> if Directory.Exists d then Directory.Delete (d, true)) |
| 35 | + |
| 36 | + do xake TestOptions { |
| 37 | + rules [ |
| 38 | + "main" => action { |
| 39 | + do! need ["cpin/samplefile"] |
| 40 | + do! Cp {CpArgs.Default with dir = "cpin"; todir = "cptgt"; flatten = true} |
| 41 | + } |
| 42 | + |
| 43 | + "cpin/samplefile" ..> writeText "hello world" |
| 44 | + ] |
| 45 | + } |
| 46 | + |
| 47 | + Assert.True <| File.Exists ("cptgt" </> "samplefile") |
| 48 | + |
| 49 | +[<Test>] |
| 50 | +let ``copies folder no flatten``() = |
| 51 | + "." </> ".xake" |> File.Delete |
| 52 | + ["cptgt"; "cpin"] |> List.map (fun d -> if Directory.Exists d then Directory.Delete (d, true)) |
| 53 | + |
| 54 | + do xake TestOptions { |
| 55 | + rules [ |
| 56 | + "main" => action { |
| 57 | + do! need ["cpin/a/samplefile"] |
| 58 | + do! Cp {CpArgs.Default with dir = "cpin"; todir = "cptgt"; flatten = false} |
| 59 | + } |
| 60 | + |
| 61 | + "cpin/a/samplefile" ..> writeText "hello world" |
| 62 | + ] |
| 63 | + } |
| 64 | + |
| 65 | + Assert.True <| File.Exists ("cptgt" </> "cpin" </> "a" </> "samplefile") |
| 66 | + |
| 67 | +[<Test>] |
| 68 | +let ``copies fileset NO flatten``() = |
| 69 | + "." </> ".xake" |> File.Delete |
| 70 | + ["cptgt"; "cpin"] |> List.map (fun d -> if Directory.Exists d then Directory.Delete (d, true)) |
| 71 | + |
| 72 | + do xake TestOptions { |
| 73 | + rules [ |
| 74 | + "main" => action { |
| 75 | + do! need ["cpin/a/samplefile"] |
| 76 | + do! Cp {CpArgs.Default with |
| 77 | + files = (fileset {basedir "cpin"; includes "**/*"}) |
| 78 | + todir = "cptgt" |
| 79 | + flatten = false |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + "cpin/a/samplefile" ..> writeText "hello world" |
| 84 | + ] |
| 85 | + } |
| 86 | + |
| 87 | + Assert.True <| File.Exists ("cptgt" </> "a" </> "samplefile") |
| 88 | + |
| 89 | +[<Test>] |
| 90 | +let ``copies fileset flatten``() = |
| 91 | + "." </> ".xake" |> File.Delete |
| 92 | + ["cptgt"; "cpin"] |> List.map (fun d -> if Directory.Exists d then Directory.Delete (d, true)) |
| 93 | + |
| 94 | + do xake TestOptions { |
| 95 | + rules [ |
| 96 | + "main" => action { |
| 97 | + do! need ["cpin/a/samplefile"] |
| 98 | + do! cp {files !!"cpin/**/*"; todir "cptgt"; flatten} |
| 99 | + } |
| 100 | + |
| 101 | + "cpin/a/samplefile" ..> writeText "hello world" |
| 102 | + ] |
| 103 | + } |
| 104 | + |
| 105 | + Assert.True <| File.Exists ("cptgt" </> "samplefile") |
0 commit comments