diff options
Diffstat (limited to 'spec/tools_spec.lua')
-rw-r--r-- | spec/tools_spec.lua | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/spec/tools_spec.lua b/spec/tools_spec.lua index c84dbab3..29e21740 100644 --- a/spec/tools_spec.lua +++ b/spec/tools_spec.lua | |||
@@ -8,7 +8,7 @@ local fs = require("luarocks.fs") | |||
8 | local cfg = require("luarocks.core.cfg") | 8 | local cfg = require("luarocks.core.cfg") |
9 | local patch = require("luarocks.tools.patch") | 9 | local patch = require("luarocks.tools.patch") |
10 | 10 | ||
11 | local lao = | 11 | local lao = |
12 | [[The Nameless is the origin of Heaven and Earth; | 12 | [[The Nameless is the origin of Heaven and Earth; |
13 | The named is the mother of all things. | 13 | The named is the mother of all things. |
14 | 14 | ||
@@ -23,7 +23,7 @@ They both may be called deep and profound. | |||
23 | Deeper and more profound, | 23 | Deeper and more profound, |
24 | The door of all subtleties!]] | 24 | The door of all subtleties!]] |
25 | 25 | ||
26 | local tzu = | 26 | local tzu = |
27 | [[The Way that can be told of is not the eternal Way; | 27 | [[The Way that can be told of is not the eternal Way; |
28 | The name that can be named is not the eternal name. | 28 | The name that can be named is not the eternal name. |
29 | The Nameless is the origin of Heaven and Earth; | 29 | The Nameless is the origin of Heaven and Earth; |
@@ -36,7 +36,7 @@ The two are the same, | |||
36 | But after they are produced, | 36 | But after they are produced, |
37 | they have different names.]] | 37 | they have different names.]] |
38 | 38 | ||
39 | local valid_patch1 = | 39 | local valid_patch1 = |
40 | [[--- lao 2002-02-21 23:30:39.942229878 -0800 | 40 | [[--- lao 2002-02-21 23:30:39.942229878 -0800 |
41 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 | 41 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 |
42 | @@ -1,7 +1,6 @@ | 42 | @@ -1,7 +1,6 @@ |
@@ -57,7 +57,7 @@ local valid_patch1 = | |||
57 | +Deeper and more profound, | 57 | +Deeper and more profound, |
58 | +The door of all subtleties!]] | 58 | +The door of all subtleties!]] |
59 | 59 | ||
60 | local valid_patch2 = | 60 | local valid_patch2 = |
61 | [[--- /dev/null 1969-02-21 23:30:39.942229878 -0800 | 61 | [[--- /dev/null 1969-02-21 23:30:39.942229878 -0800 |
62 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 | 62 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 |
63 | @@ -1,7 +1,6 @@ | 63 | @@ -1,7 +1,6 @@ |
@@ -78,7 +78,7 @@ local valid_patch2 = | |||
78 | +Deeper and more profound, | 78 | +Deeper and more profound, |
79 | +The door of all subtleties!]] | 79 | +The door of all subtleties!]] |
80 | 80 | ||
81 | local invalid_patch1 = | 81 | local invalid_patch1 = |
82 | [[--- lao 2002-02-21 23:30:39.942229878 -0800 | 82 | [[--- lao 2002-02-21 23:30:39.942229878 -0800 |
83 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 | 83 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 |
84 | @@ -1,7 +1,6 @@ | 84 | @@ -1,7 +1,6 @@ |
@@ -101,7 +101,7 @@ local invalid_patch1 = | |||
101 | +Deeper and more profound, | 101 | +Deeper and more profound, |
102 | +The door of all subtleties!]] | 102 | +The door of all subtleties!]] |
103 | 103 | ||
104 | local invalid_patch2 = | 104 | local invalid_patch2 = |
105 | [[--- lao 2002-02-21 23:30:39.942229878 -0800 | 105 | [[--- lao 2002-02-21 23:30:39.942229878 -0800 |
106 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 | 106 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 |
107 | @@ -1,7 +1,6 @@ | 107 | @@ -1,7 +1,6 @@ |
@@ -123,7 +123,7 @@ local invalid_patch2 = | |||
123 | ? ... | 123 | ? ... |
124 | +The door of all subtleties!]] | 124 | +The door of all subtleties!]] |
125 | 125 | ||
126 | local invalid_patch3 = | 126 | local invalid_patch3 = |
127 | [[--- lao 2002-02-21 23:30:39.942229878 -0800 | 127 | [[--- lao 2002-02-21 23:30:39.942229878 -0800 |
128 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 | 128 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 |
129 | @@ -1,7 +1,6 @@ | 129 | @@ -1,7 +1,6 @@ |
@@ -147,7 +147,7 @@ local invalid_patch3 = | |||
147 | 147 | ||
148 | describe("Luarocks patch test #unit", function() | 148 | describe("Luarocks patch test #unit", function() |
149 | local runner | 149 | local runner |
150 | 150 | ||
151 | setup(function() | 151 | setup(function() |
152 | cfg.init() | 152 | cfg.init() |
153 | fs.init() | 153 | fs.init() |
@@ -155,51 +155,51 @@ describe("Luarocks patch test #unit", function() | |||
155 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | 155 | runner.init(testing_paths.testrun_dir .. "/luacov.config") |
156 | runner.tick = true | 156 | runner.tick = true |
157 | end) | 157 | end) |
158 | 158 | ||
159 | teardown(function() | 159 | teardown(function() |
160 | runner.shutdown() | 160 | runner.shutdown() |
161 | end) | 161 | end) |
162 | 162 | ||
163 | describe("patch.read_patch", function() | 163 | describe("patch.read_patch", function() |
164 | it("returns a table with the patch file info and the result of parsing the file", function() | 164 | it("returns a table with the patch file info and the result of parsing the file", function() |
165 | local t, result | 165 | local t, result |
166 | 166 | ||
167 | write_file("test.patch", valid_patch1, finally) | 167 | write_file("test.patch", valid_patch1, finally) |
168 | t, result = patch.read_patch("test.patch") | 168 | t, result = patch.read_patch("test.patch") |
169 | assert.truthy(result) | 169 | assert.truthy(result) |
170 | assert.truthy(t) | 170 | assert.truthy(t) |
171 | 171 | ||
172 | write_file("test.patch", invalid_patch1, finally) | 172 | write_file("test.patch", invalid_patch1, finally) |
173 | t, result = patch.read_patch("test.patch") | 173 | t, result = patch.read_patch("test.patch") |
174 | assert.falsy(result) | 174 | assert.falsy(result) |
175 | assert.truthy(t) | 175 | assert.truthy(t) |
176 | 176 | ||
177 | write_file("test.patch", invalid_patch2, finally) | 177 | write_file("test.patch", invalid_patch2, finally) |
178 | t, result = patch.read_patch("test.patch") | 178 | t, result = patch.read_patch("test.patch") |
179 | assert.falsy(result) | 179 | assert.falsy(result) |
180 | assert.truthy(t) | 180 | assert.truthy(t) |
181 | 181 | ||
182 | write_file("test.patch", invalid_patch3, finally) | 182 | write_file("test.patch", invalid_patch3, finally) |
183 | t, result = patch.read_patch("test.patch") | 183 | t, result = patch.read_patch("test.patch") |
184 | assert.falsy(result) | 184 | assert.falsy(result) |
185 | assert.truthy(t) | 185 | assert.truthy(t) |
186 | end) | 186 | end) |
187 | end) | 187 | end) |
188 | 188 | ||
189 | describe("patch.apply_patch", function() | 189 | describe("patch.apply_patch", function() |
190 | local tmpdir | 190 | local tmpdir |
191 | local olddir | 191 | local olddir |
192 | 192 | ||
193 | before_each(function() | 193 | before_each(function() |
194 | tmpdir = get_tmp_path() | 194 | tmpdir = get_tmp_path() |
195 | olddir = lfs.currentdir() | 195 | olddir = lfs.currentdir() |
196 | lfs.mkdir(tmpdir) | 196 | lfs.mkdir(tmpdir) |
197 | lfs.chdir(tmpdir) | 197 | lfs.chdir(tmpdir) |
198 | 198 | ||
199 | write_file("lao", tzu, finally) | 199 | write_file("lao", tzu, finally) |
200 | write_file("tzu", lao, finally) | 200 | write_file("tzu", lao, finally) |
201 | end) | 201 | end) |
202 | 202 | ||
203 | after_each(function() | 203 | after_each(function() |
204 | if olddir then | 204 | if olddir then |
205 | lfs.chdir(olddir) | 205 | lfs.chdir(olddir) |
@@ -208,44 +208,44 @@ describe("Luarocks patch test #unit", function() | |||
208 | end | 208 | end |
209 | end | 209 | end |
210 | end) | 210 | end) |
211 | 211 | ||
212 | it("applies the given patch and returns the result of patching", function() | 212 | it("applies the given patch and returns the result of patching", function() |
213 | write_file("test.patch", valid_patch1, finally) | 213 | write_file("test.patch", valid_patch1, finally) |
214 | local p = patch.read_patch("test.patch") | 214 | local p = patch.read_patch("test.patch") |
215 | local result = patch.apply_patch(p) | 215 | local result = patch.apply_patch(p) |
216 | assert.truthy(result) | 216 | assert.truthy(result) |
217 | end) | 217 | end) |
218 | 218 | ||
219 | it("applies the given patch with custom arguments and returns the result of patching", function() | 219 | it("applies the given patch with custom arguments and returns the result of patching", function() |
220 | write_file("test.patch", valid_patch2, finally) | 220 | write_file("test.patch", valid_patch2, finally) |
221 | local p = patch.read_patch("test.patch") | 221 | local p = patch.read_patch("test.patch") |
222 | local result = patch.apply_patch(p, nil, true) | 222 | local result = patch.apply_patch(p, nil, true) |
223 | assert.truthy(result) | 223 | assert.truthy(result) |
224 | end) | 224 | end) |
225 | 225 | ||
226 | it("fails if the patch file is invalid", function() | 226 | it("fails if the patch file is invalid", function() |
227 | write_file("test.patch", invalid_patch1, finally) | 227 | write_file("test.patch", invalid_patch1, finally) |
228 | local p = patch.read_patch("test.patch") | 228 | local p = patch.read_patch("test.patch") |
229 | local result = pcall(patch.apply_patch, p) | 229 | local result = pcall(patch.apply_patch, p) |
230 | assert.falsy(result) | 230 | assert.falsy(result) |
231 | end) | 231 | end) |
232 | 232 | ||
233 | it("returns false if the files from the patch doesn't exist", function() | 233 | it("returns false if the files from the patch doesn't exist", function() |
234 | os.remove("lao") | 234 | os.remove("lao") |
235 | os.remove("tzu") | 235 | os.remove("tzu") |
236 | 236 | ||
237 | write_file("test.patch", valid_patch1, finally) | 237 | write_file("test.patch", valid_patch1, finally) |
238 | local p = patch.read_patch("test.patch") | 238 | local p = patch.read_patch("test.patch") |
239 | local result = patch.apply_patch(p) | 239 | local result = patch.apply_patch(p) |
240 | assert.falsy(result) | 240 | assert.falsy(result) |
241 | end) | 241 | end) |
242 | 242 | ||
243 | it("returns false if the target file was already patched", function() | 243 | it("returns false if the target file was already patched", function() |
244 | write_file("test.patch", valid_patch1, finally) | 244 | write_file("test.patch", valid_patch1, finally) |
245 | local p = patch.read_patch("test.patch") | 245 | local p = patch.read_patch("test.patch") |
246 | local result = patch.apply_patch(p) | 246 | local result = patch.apply_patch(p) |
247 | assert.truthy(result) | 247 | assert.truthy(result) |
248 | 248 | ||
249 | result = patch.apply_patch(p) | 249 | result = patch.apply_patch(p) |
250 | assert.falsy(result) | 250 | assert.falsy(result) |
251 | end) | 251 | end) |