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/tools_spec.lua | |
| parent | a60bd09ffda9c36443cf64c4c1f14d1c09442148 (diff) | |
| download | luarocks-c01c8a21a735c3a74270635e5bd843bac71bc624.tar.gz luarocks-c01c8a21a735c3a74270635e5bd843bac71bc624.tar.bz2 luarocks-c01c8a21a735c3a74270635e5bd843bac71bc624.zip | |
Tests: patch.lua
Diffstat (limited to 'spec/tools_spec.lua')
| -rw-r--r-- | spec/tools_spec.lua | 88 |
1 files changed, 88 insertions, 0 deletions
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) | ||
