diff options
author | George Roman <george.roman.99@gmail.com> | 2018-06-17 09:50:17 +0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-20 11:25:10 -0300 |
commit | 010b42ff0949c9e5ad56809389340b3c25abc3a9 (patch) | |
tree | f39fac8e16fb62f1bdea51ac816024e6be3d7894 | |
parent | bfcb8a9e0826c745efe0189a4b5e8d156fb78684 (diff) | |
download | luarocks-010b42ff0949c9e5ad56809389340b3c25abc3a9.tar.gz luarocks-010b42ff0949c9e5ad56809389340b3c25abc3a9.tar.bz2 luarocks-010b42ff0949c9e5ad56809389340b3c25abc3a9.zip |
Tests: improve patch.lua tests
-rw-r--r-- | spec/fixtures/invalid_patch.patch | 20 | ||||
-rw-r--r-- | spec/fixtures/lao | 11 | ||||
-rw-r--r-- | spec/fixtures/tzu | 13 | ||||
-rw-r--r-- | spec/fixtures/valid_patch.patch | 19 | ||||
-rw-r--r-- | spec/tools_spec.lua | 198 |
5 files changed, 180 insertions, 81 deletions
diff --git a/spec/fixtures/invalid_patch.patch b/spec/fixtures/invalid_patch.patch deleted file mode 100644 index 75d05c58..00000000 --- a/spec/fixtures/invalid_patch.patch +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | --- lao 2002-02-21 23:30:39.942229878 -0800 | ||
2 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 | ||
3 | @@ -1,7 +1,6 @@ | ||
4 | -The Way that can be told of is not the eternal Way; | ||
5 | -The name that can be named is not the eternal name. | ||
6 | The Nameless is the origin of Heaven and Earth; | ||
7 | -The Named is the mother of all things. | ||
8 | +The named is the mother of all things. | ||
9 | + | ||
10 | ? | ||
11 | Therefore let there always be non-being, | ||
12 | so we may see their subtlety, | ||
13 | And let there always be being, | ||
14 | @@ -9,3 +8,7 @@ | ||
15 | The two are the same, | ||
16 | But after they are produced, | ||
17 | they have different names. | ||
18 | +They both may be called deep and profound. | ||
19 | +Deeper and more profound, | ||
20 | +The door of all subtleties! | ||
diff --git a/spec/fixtures/lao b/spec/fixtures/lao deleted file mode 100644 index 635ef2c4..00000000 --- a/spec/fixtures/lao +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | The Way that can be told of is not the eternal Way; | ||
2 | The name that can be named is not the eternal name. | ||
3 | The Nameless is the origin of Heaven and Earth; | ||
4 | The Named is the mother of all things. | ||
5 | Therefore let there always be non-being, | ||
6 | so we may see their subtlety, | ||
7 | And let there always be being, | ||
8 | so we may see their outcome. | ||
9 | The two are the same, | ||
10 | But after they are produced, | ||
11 | they have different names. | ||
diff --git a/spec/fixtures/tzu b/spec/fixtures/tzu deleted file mode 100644 index 5af88a8f..00000000 --- a/spec/fixtures/tzu +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | The Nameless is the origin of Heaven and Earth; | ||
2 | The named is the mother of all things. | ||
3 | |||
4 | Therefore let there always be non-being, | ||
5 | so we may see their subtlety, | ||
6 | And let there always be being, | ||
7 | so we may see their outcome. | ||
8 | The two are the same, | ||
9 | But after they are produced, | ||
10 | they have different names. | ||
11 | They both may be called deep and profound. | ||
12 | Deeper and more profound, | ||
13 | The door of all subtleties! | ||
diff --git a/spec/fixtures/valid_patch.patch b/spec/fixtures/valid_patch.patch deleted file mode 100644 index 042c7d22..00000000 --- a/spec/fixtures/valid_patch.patch +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | --- lao 2002-02-21 23:30:39.942229878 -0800 | ||
2 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 | ||
3 | @@ -1,7 +1,6 @@ | ||
4 | -The Way that can be told of is not the eternal Way; | ||
5 | -The name that can be named is not the eternal name. | ||
6 | The Nameless is the origin of Heaven and Earth; | ||
7 | -The Named is the mother of all things. | ||
8 | +The named is the mother of all things. | ||
9 | + | ||
10 | Therefore let there always be non-being, | ||
11 | so we may see their subtlety, | ||
12 | And let there always be being, | ||
13 | @@ -9,3 +8,6 @@ | ||
14 | The two are the same, | ||
15 | But after they are produced, | ||
16 | they have different names. | ||
17 | +They both may be called deep and profound. | ||
18 | +Deeper and more profound, | ||
19 | +The door of all subtleties! | ||
diff --git a/spec/tools_spec.lua b/spec/tools_spec.lua index 7717be08..8805d703 100644 --- a/spec/tools_spec.lua +++ b/spec/tools_spec.lua | |||
@@ -1,12 +1,149 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | local testing_paths = test_env.testing_paths | ||
3 | local get_tmp_path = test_env.get_tmp_path | 2 | local get_tmp_path = test_env.get_tmp_path |
3 | local testing_paths = test_env.testing_paths | ||
4 | local write_file = test_env.write_file | 4 | local write_file = test_env.write_file |
5 | 5 | ||
6 | test_env.unload_luarocks() | 6 | test_env.unload_luarocks() |
7 | local fs = require("luarocks.fs") | 7 | local fs = require("luarocks.fs") |
8 | local patch = package.loaded["luarocks.tools.patch"] | 8 | local patch = package.loaded["luarocks.tools.patch"] |
9 | 9 | ||
10 | local lao = | ||
11 | [[The Nameless is the origin of Heaven and Earth; | ||
12 | The named is the mother of all things. | ||
13 | |||
14 | Therefore let there always be non-being, | ||
15 | so we may see their subtlety, | ||
16 | And let there always be being, | ||
17 | so we may see their outcome. | ||
18 | The two are the same, | ||
19 | But after they are produced, | ||
20 | they have different names. | ||
21 | They both may be called deep and profound. | ||
22 | Deeper and more profound, | ||
23 | The door of all subtleties!]] | ||
24 | |||
25 | local tzu = | ||
26 | [[The Way that can be told of is not the eternal Way; | ||
27 | The name that can be named is not the eternal name. | ||
28 | The Nameless is the origin of Heaven and Earth; | ||
29 | The Named is the mother of all things. | ||
30 | Therefore let there always be non-being, | ||
31 | so we may see their subtlety, | ||
32 | And let there always be being, | ||
33 | so we may see their outcome. | ||
34 | The two are the same, | ||
35 | But after they are produced, | ||
36 | they have different names.]] | ||
37 | |||
38 | local valid_patch1 = | ||
39 | [[--- lao 2002-02-21 23:30:39.942229878 -0800 | ||
40 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 | ||
41 | @@ -1,7 +1,6 @@ | ||
42 | -The Way that can be told of is not the eternal Way; | ||
43 | -The name that can be named is not the eternal name. | ||
44 | The Nameless is the origin of Heaven and Earth; | ||
45 | -The Named is the mother of all things. | ||
46 | +The named is the mother of all things. | ||
47 | + | ||
48 | Therefore let there always be non-being, | ||
49 | so we may see their subtlety, | ||
50 | And let there always be being, | ||
51 | @@ -9,3 +8,6 @@ | ||
52 | The two are the same, | ||
53 | But after they are produced, | ||
54 | they have different names. | ||
55 | +They both may be called deep and profound. | ||
56 | +Deeper and more profound, | ||
57 | +The door of all subtleties!]] | ||
58 | |||
59 | local valid_patch2 = | ||
60 | [[--- /dev/null 1969-02-21 23:30:39.942229878 -0800 | ||
61 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 | ||
62 | @@ -1,7 +1,6 @@ | ||
63 | -The Way that can be told of is not the eternal Way; | ||
64 | -The name that can be named is not the eternal name. | ||
65 | The Nameless is the origin of Heaven and Earth; | ||
66 | -The Named is the mother of all things. | ||
67 | +The named is the mother of all things. | ||
68 | + | ||
69 | Therefore let there always be non-being, | ||
70 | so we may see their subtlety, | ||
71 | And let there always be being, | ||
72 | @@ -9,3 +8,6 @@ | ||
73 | The two are the same, | ||
74 | But after they are produced, | ||
75 | they have different names. | ||
76 | +They both may be called deep and profound. | ||
77 | +Deeper and more profound, | ||
78 | +The door of all subtleties!]] | ||
79 | |||
80 | local invalid_patch1 = | ||
81 | [[--- lao 2002-02-21 23:30:39.942229878 -0800 | ||
82 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 | ||
83 | @@ -1,7 +1,6 @@ | ||
84 | -The Way that can be told of is not the eternal Way; | ||
85 | -The name that can be named is not the eternal name. | ||
86 | The Nameless is the origin of Heaven and Earth; | ||
87 | -The Named is the mother of all things. | ||
88 | --- Extra | ||
89 | +The named is the mother of all things. | ||
90 | + | ||
91 | Therefore let there always be non-being, | ||
92 | so we may see their subtlety, | ||
93 | And let there always be being, | ||
94 | --- Extra | ||
95 | @@ -9,3 +8,7 @@ | ||
96 | The two are the same, | ||
97 | But after they are produced, | ||
98 | they have different names. | ||
99 | +They both may be called deep and profound. | ||
100 | +Deeper and more profound, | ||
101 | +The door of all subtleties!]] | ||
102 | |||
103 | local invalid_patch2 = | ||
104 | [[--- lao 2002-02-21 23:30:39.942229878 -0800 | ||
105 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 | ||
106 | @@ -1,7 +1,6 @@ | ||
107 | -The Way that can be told of is not the eternal Way; | ||
108 | -The name that can be named is not the eternal name. | ||
109 | The Nameless is the origin of Heaven and Earth; | ||
110 | -The Named is the mother of all things. | ||
111 | +The named is the mother of all things. | ||
112 | + | ||
113 | Therefore let there always be non-being, | ||
114 | so we may see their subtlety, | ||
115 | And let there always be being, | ||
116 | @@ -9,3 +8,6 @@ | ||
117 | The two are the same, | ||
118 | But after they are produced, | ||
119 | they have different names. | ||
120 | +They both may be called deep and profound. | ||
121 | +Deeper and more profound, | ||
122 | ? ... | ||
123 | +The door of all subtleties!]] | ||
124 | |||
125 | local invalid_patch3 = | ||
126 | [[--- lao 2002-02-21 23:30:39.942229878 -0800 | ||
127 | +++ tzu 2002-02-21 23:30:50.442260588 -0800 | ||
128 | @@ -1,7 +1,6 @@ | ||
129 | -The Way that can be told of is not the eternal Way; | ||
130 | -The name that can be named is not the eternal name. | ||
131 | The Nameless is the origin of Heaven and Earth; | ||
132 | -The Named is the mother of all things. | ||
133 | +The named is the mother of all things. | ||
134 | + | ||
135 | Therefore let there always be non-being, | ||
136 | so we may see their subtlety, | ||
137 | And let there always be being, | ||
138 | @@ -9,3 +8,6 @@ | ||
139 | The two are the same, | ||
140 | But after they are produced, | ||
141 | they have different names. | ||
142 | +They both may be called deep and profound. | ||
143 | +Deeper and more profound, | ||
144 | ? ... | ||
145 | +The door of all subtleties!]] | ||
146 | |||
10 | describe("Luarocks patch test #unit", function() | 147 | describe("Luarocks patch test #unit", function() |
11 | local runner | 148 | local runner |
12 | 149 | ||
@@ -24,11 +161,25 @@ describe("Luarocks patch test #unit", function() | |||
24 | it("returns a table with the patch file info and the result of parsing the file", function() | 161 | it("returns a table with the patch file info and the result of parsing the file", function() |
25 | local t, result | 162 | local t, result |
26 | 163 | ||
27 | t, result = patch.read_patch(testing_paths.fixtures_dir .. "/valid_patch.patch") | 164 | write_file("test.patch", valid_patch1, finally) |
165 | t, result = patch.read_patch("test.patch") | ||
28 | assert.truthy(result) | 166 | assert.truthy(result) |
167 | assert.truthy(t) | ||
168 | |||
169 | write_file("test.patch", invalid_patch1, finally) | ||
170 | t, result = patch.read_patch("test.patch") | ||
171 | assert.falsy(result) | ||
172 | assert.truthy(t) | ||
173 | |||
174 | write_file("test.patch", invalid_patch2, finally) | ||
175 | t, result = patch.read_patch("test.patch") | ||
176 | assert.falsy(result) | ||
177 | assert.truthy(t) | ||
29 | 178 | ||
30 | t, result = patch.read_patch(testing_paths.fixtures_dir .. "/invalid_patch.patch") | 179 | write_file("test.patch", invalid_patch3, finally) |
180 | t, result = patch.read_patch("test.patch") | ||
31 | assert.falsy(result) | 181 | assert.falsy(result) |
182 | assert.truthy(t) | ||
32 | end) | 183 | end) |
33 | end) | 184 | end) |
34 | 185 | ||
@@ -42,15 +193,8 @@ describe("Luarocks patch test #unit", function() | |||
42 | lfs.mkdir(tmpdir) | 193 | lfs.mkdir(tmpdir) |
43 | lfs.chdir(tmpdir) | 194 | lfs.chdir(tmpdir) |
44 | 195 | ||
45 | local fd = assert(io.open(testing_paths.fixtures_dir .. "/lao")) | 196 | write_file("lao", tzu, finally) |
46 | local laocontent = assert(fd:read("*a")) | 197 | write_file("tzu", lao, finally) |
47 | fd:close() | ||
48 | write_file("lao", laocontent, finally) | ||
49 | |||
50 | fd = assert(io.open(testing_paths.fixtures_dir .. "/tzu")) | ||
51 | local tzucontent = assert(fd:read("*a")) | ||
52 | fd:close() | ||
53 | write_file("tzu", tzucontent, finally) | ||
54 | end) | 198 | end) |
55 | 199 | ||
56 | after_each(function() | 200 | after_each(function() |
@@ -62,22 +206,40 @@ describe("Luarocks patch test #unit", function() | |||
62 | end | 206 | end |
63 | end) | 207 | end) |
64 | 208 | ||
65 | it("applies the given patch and returns true if the patch is valid", function() | 209 | it("applies the given patch and returns the result of patching", function() |
66 | local p = patch.read_patch(testing_paths.fixtures_dir .. "/valid_patch.patch") | 210 | write_file("test.patch", valid_patch1, finally) |
211 | local p = patch.read_patch("test.patch") | ||
67 | local result = patch.apply_patch(p) | 212 | local result = patch.apply_patch(p) |
68 | assert.truthy(result) | 213 | assert.truthy(result) |
69 | end) | 214 | end) |
70 | 215 | ||
71 | it("returns false if the files to be patched are not valid or doesn't exist", function() | 216 | it("applies the given patch with custom arguments and returns the result of patching", function() |
217 | write_file("test.patch", valid_patch2, finally) | ||
218 | local p = patch.read_patch("test.patch") | ||
219 | local result = patch.apply_patch(p, nil, true) | ||
220 | assert.truthy(result) | ||
221 | end) | ||
222 | |||
223 | it("fails if the patch file is invalid", function() | ||
224 | write_file("test.patch", invalid_patch1, finally) | ||
225 | local p = patch.read_patch("test.patch") | ||
226 | local result = pcall(patch.apply_patch, p) | ||
227 | assert.falsy(result) | ||
228 | end) | ||
229 | |||
230 | it("returns false if the files from the patch doesn't exist", function() | ||
72 | os.remove("lao") | 231 | os.remove("lao") |
73 | os.remove("tzu") | 232 | os.remove("tzu") |
74 | local p = patch.read_patch(testing_paths.fixtures_dir .. "/invalid_patch.patch") | 233 | |
234 | write_file("test.patch", valid_patch1, finally) | ||
235 | local p = patch.read_patch("test.patch") | ||
75 | local result = patch.apply_patch(p) | 236 | local result = patch.apply_patch(p) |
76 | assert.falsy(result) | 237 | assert.falsy(result) |
77 | end) | 238 | end) |
78 | 239 | ||
79 | it("returns false if the target file is already patched", function() | 240 | it("returns false if the target file was already patched", function() |
80 | local p = patch.read_patch(testing_paths.fixtures_dir .. "/valid_patch.patch") | 241 | write_file("test.patch", valid_patch1, finally) |
242 | local p = patch.read_patch("test.patch") | ||
81 | local result = patch.apply_patch(p) | 243 | local result = patch.apply_patch(p) |
82 | assert.truthy(result) | 244 | assert.truthy(result) |
83 | 245 | ||