diff options
| author | George Roman <george.roman.99@gmail.com> | 2018-06-13 20:09:07 +0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-14 14:14:44 -0300 |
| commit | c01c8a21a735c3a74270635e5bd843bac71bc624 (patch) | |
| tree | 64218be890422d910632e0260bf4c48e02991b3e /spec | |
| parent | a60bd09ffda9c36443cf64c4c1f14d1c09442148 (diff) | |
| download | luarocks-c01c8a21a735c3a74270635e5bd843bac71bc624.tar.gz luarocks-c01c8a21a735c3a74270635e5bd843bac71bc624.tar.bz2 luarocks-c01c8a21a735c3a74270635e5bd843bac71bc624.zip | |
Tests: patch.lua
Diffstat (limited to 'spec')
| -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 | 88 |
5 files changed, 151 insertions, 0 deletions
diff --git a/spec/fixtures/invalid_patch.patch b/spec/fixtures/invalid_patch.patch new file mode 100644 index 00000000..75d05c58 --- /dev/null +++ b/spec/fixtures/invalid_patch.patch | |||
| @@ -0,0 +1,20 @@ | |||
| 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 new file mode 100644 index 00000000..635ef2c4 --- /dev/null +++ b/spec/fixtures/lao | |||
| @@ -0,0 +1,11 @@ | |||
| 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 new file mode 100644 index 00000000..5af88a8f --- /dev/null +++ b/spec/fixtures/tzu | |||
| @@ -0,0 +1,13 @@ | |||
| 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 new file mode 100644 index 00000000..042c7d22 --- /dev/null +++ b/spec/fixtures/valid_patch.patch | |||
| @@ -0,0 +1,19 @@ | |||
| 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 new file mode 100644 index 00000000..7717be08 --- /dev/null +++ b/spec/tools_spec.lua | |||
| @@ -0,0 +1,88 @@ | |||
| 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 | ||
| 4 | local write_file = test_env.write_file | ||
| 5 | |||
| 6 | test_env.unload_luarocks() | ||
| 7 | local fs = require("luarocks.fs") | ||
| 8 | local patch = package.loaded["luarocks.tools.patch"] | ||
| 9 | |||
| 10 | describe("Luarocks patch test #unit", function() | ||
| 11 | local runner | ||
| 12 | |||
| 13 | setup(function() | ||
| 14 | runner = require("luacov.runner") | ||
| 15 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | ||
| 16 | runner.tick = true | ||
| 17 | end) | ||
| 18 | |||
| 19 | teardown(function() | ||
| 20 | runner.shutdown() | ||
| 21 | end) | ||
| 22 | |||
| 23 | describe("patch.read_patch", function() | ||
| 24 | it("returns a table with the patch file info and the result of parsing the file", function() | ||
| 25 | local t, result | ||
| 26 | |||
| 27 | t, result = patch.read_patch(testing_paths.fixtures_dir .. "/valid_patch.patch") | ||
| 28 | assert.truthy(result) | ||
| 29 | |||
| 30 | t, result = patch.read_patch(testing_paths.fixtures_dir .. "/invalid_patch.patch") | ||
| 31 | assert.falsy(result) | ||
| 32 | end) | ||
| 33 | end) | ||
| 34 | |||
| 35 | describe("patch.apply_patch", function() | ||
| 36 | local tmpdir | ||
| 37 | local olddir | ||
| 38 | |||
| 39 | before_each(function() | ||
| 40 | tmpdir = get_tmp_path() | ||
| 41 | olddir = lfs.currentdir() | ||
| 42 | lfs.mkdir(tmpdir) | ||
| 43 | lfs.chdir(tmpdir) | ||
| 44 | |||
| 45 | local fd = assert(io.open(testing_paths.fixtures_dir .. "/lao")) | ||
| 46 | local laocontent = assert(fd:read("*a")) | ||
| 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) | ||
| 55 | |||
| 56 | after_each(function() | ||
| 57 | if olddir then | ||
| 58 | lfs.chdir(olddir) | ||
| 59 | if tmpdir then | ||
| 60 | lfs.rmdir(tmpdir) | ||
| 61 | end | ||
| 62 | end | ||
| 63 | end) | ||
| 64 | |||
| 65 | it("applies the given patch and returns true if the patch is valid", function() | ||
| 66 | local p = patch.read_patch(testing_paths.fixtures_dir .. "/valid_patch.patch") | ||
| 67 | local result = patch.apply_patch(p) | ||
| 68 | assert.truthy(result) | ||
| 69 | end) | ||
| 70 | |||
| 71 | it("returns false if the files to be patched are not valid or doesn't exist", function() | ||
| 72 | os.remove("lao") | ||
| 73 | os.remove("tzu") | ||
| 74 | local p = patch.read_patch(testing_paths.fixtures_dir .. "/invalid_patch.patch") | ||
| 75 | local result = patch.apply_patch(p) | ||
| 76 | assert.falsy(result) | ||
| 77 | end) | ||
| 78 | |||
| 79 | it("returns false if the target file is already patched", function() | ||
| 80 | local p = patch.read_patch(testing_paths.fixtures_dir .. "/valid_patch.patch") | ||
| 81 | local result = patch.apply_patch(p) | ||
| 82 | assert.truthy(result) | ||
| 83 | |||
| 84 | result = patch.apply_patch(p) | ||
| 85 | assert.falsy(result) | ||
| 86 | end) | ||
| 87 | end) | ||
| 88 | end) | ||
