summaryrefslogtreecommitdiff
path: root/spec/init_spec.lua
diff options
context:
space:
mode:
authorGeorge Roman <george.roman.99@gmail.com>2018-07-24 11:09:42 +0300
committerHisham Muhammad <hisham@gobolinux.org>2018-07-24 15:41:22 -0300
commit8e6a83911027de167d689d060ce581f653d73213 (patch)
tree622218f964f10a27b7922bcfcd3bf14fd6c1735b /spec/init_spec.lua
parent961670659be3e986bc74b9b8c2a296f4640302e5 (diff)
downloadluarocks-8e6a83911027de167d689d060ce581f653d73213.tar.gz
luarocks-8e6a83911027de167d689d060ce581f653d73213.tar.bz2
luarocks-8e6a83911027de167d689d060ce581f653d73213.zip
Tests: add test_env.run_in_tmp utility function
Diffstat (limited to 'spec/init_spec.lua')
-rw-r--r--spec/init_spec.lua109
1 files changed, 45 insertions, 64 deletions
diff --git a/spec/init_spec.lua b/spec/init_spec.lua
index 2d28bfe7..a4751741 100644
--- a/spec/init_spec.lua
+++ b/spec/init_spec.lua
@@ -8,76 +8,57 @@ local is_win = test_env.TEST_TARGET_OS == "windows"
8test_env.unload_luarocks() 8test_env.unload_luarocks()
9 9
10describe("Luarocks init test #integration", function() 10describe("Luarocks init test #integration", function()
11 local tmpdir
12
13 after_each(function()
14 if tmpdir then
15 lfs.rmdir(tmpdir)
16 tmpdir = nil
17 end
18 end)
19
20 it("LuaRocks init with no arguments", function() 11 it("LuaRocks init with no arguments", function()
21 tmpdir = get_tmp_path() 12 test_env.run_in_tmp(function(tmpdir)
22 lfs.mkdir(tmpdir) 13 local myproject = tmpdir .. "/myproject"
23 local myproject = tmpdir .. "/myproject" 14 lfs.mkdir(myproject)
24 lfs.mkdir(myproject) 15 lfs.chdir(myproject)
25 local olddir = lfs.currentdir() 16
26 lfs.chdir(myproject) 17 assert(run.luarocks("init"))
27 18 if is_win then
28 assert(run.luarocks("init")) 19 assert.truthy(lfs.attributes(myproject .. "/lua.bat"))
29 if is_win then 20 assert.truthy(lfs.attributes(myproject .. "/luarocks.bat"))
30 assert.truthy(lfs.attributes(myproject .. "/lua.bat")) 21 else
31 assert.truthy(lfs.attributes(myproject .. "/luarocks.bat")) 22 assert.truthy(lfs.attributes(myproject .. "/lua"))
32 else 23 assert.truthy(lfs.attributes(myproject .. "/luarocks"))
33 assert.truthy(lfs.attributes(myproject .. "/lua")) 24 end
34 assert.truthy(lfs.attributes(myproject .. "/luarocks")) 25 assert.truthy(lfs.attributes(myproject .. "/lua_modules"))
35 end 26 assert.truthy(lfs.attributes(myproject .. "/.luarocks"))
36 assert.truthy(lfs.attributes(myproject .. "/lua_modules")) 27 assert.truthy(lfs.attributes(myproject .. "/.luarocks/config-" .. test_env.lua_version .. ".lua"))
37 assert.truthy(lfs.attributes(myproject .. "/.luarocks")) 28 assert.truthy(lfs.attributes(myproject .. "/.gitignore"))
38 assert.truthy(lfs.attributes(myproject .. "/.luarocks/config-" .. test_env.lua_version .. ".lua")) 29 assert.truthy(lfs.attributes(myproject .. "/myproject-dev-1.rockspec"))
39 assert.truthy(lfs.attributes(myproject .. "/.gitignore")) 30 end, finally)
40 assert.truthy(lfs.attributes(myproject .. "/myproject-dev-1.rockspec"))
41
42 lfs.chdir(olddir)
43 end) 31 end)
44 32
45 it("LuaRocks init with given arguments", function() 33 it("LuaRocks init with given arguments", function()
46 tmpdir = get_tmp_path() 34 test_env.run_in_tmp(function(tmpdir)
47 lfs.mkdir(tmpdir) 35 local myproject = tmpdir .. "/myproject"
48 local myproject = tmpdir .. "/myproject" 36 lfs.mkdir(myproject)
49 lfs.mkdir(myproject) 37 lfs.chdir(myproject)
50 local olddir = lfs.currentdir() 38
51 lfs.chdir(myproject) 39 assert(run.luarocks("init customname 1.0"))
52 40 assert.truthy(lfs.attributes(myproject .. "/customname-1.0-1.rockspec"))
53 assert(run.luarocks("init customname 1.0")) 41 end, finally)
54 assert.truthy(lfs.attributes(myproject .. "/customname-1.0-1.rockspec"))
55
56 lfs.chdir(olddir)
57 end) 42 end)
58 43
59 it("LuaRocks init in a git repo", function() 44 it("LuaRocks init in a git repo", function()
60 tmpdir = get_tmp_path() 45 test_env.run_in_tmp(function(tmpdir)
61 lfs.mkdir(tmpdir) 46 local myproject = tmpdir .. "/myproject"
62 local olddir = lfs.currentdir() 47 copy_dir(testing_paths.fixtures_dir .. "/git_repo", myproject)
63 lfs.chdir(tmpdir) 48 lfs.chdir(myproject)
64 local myproject = tmpdir .. "/myproject" 49
65 copy_dir(testing_paths.fixtures_dir .. "/git_repo", myproject) 50 assert(run.luarocks("init"))
66 lfs.chdir(myproject) 51 local fd = assert(io.open(myproject .. "/myproject-dev-1.rockspec", "r"))
67 52 local content = assert(fd:read("*a"))
68 assert(run.luarocks("init")) 53 assert.truthy(content:find("summary = \"Test repo\""))
69 local fd = assert(io.open(myproject .. "/myproject-dev-1.rockspec", "r")) 54 assert.truthy(content:find("detailed = .+Test repo.+"))
70 local content = assert(fd:read("*a")) 55 assert.truthy(content:find("license = \"MIT\""))
71 assert.truthy(content:find("summary = \"Test repo\"")) 56
72 assert.truthy(content:find("detailed = .+Test repo.+")) 57 fd = assert(io.open(myproject .. "/.gitignore", "r"))
73 assert.truthy(content:find("license = \"MIT\"")) 58 content = assert(fd:read("*a"))
74 59 assert.truthy(content:find("/foo"))
75 fd = assert(io.open(myproject .. "/.gitignore", "r")) 60 assert.truthy(content:find("/lua"))
76 content = assert(fd:read("*a")) 61 assert.truthy(content:find("/lua_modules"))
77 assert.truthy(content:find("/foo")) 62 end, finally)
78 assert.truthy(content:find("/lua"))
79 assert.truthy(content:find("/lua_modules"))
80
81 lfs.chdir(olddir)
82 end) 63 end)
83end) 64end)