aboutsummaryrefslogtreecommitdiff
path: root/spec/init_spec.lua
blob: a475174169d3378f6a26fbefe0899c58c2caa94b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
local test_env = require("spec.util.test_env")
local run = test_env.run
local testing_paths = test_env.testing_paths
local get_tmp_path = test_env.get_tmp_path
local copy_dir = test_env.copy_dir
local is_win = test_env.TEST_TARGET_OS == "windows"

test_env.unload_luarocks()

describe("Luarocks init test #integration", function()
   it("LuaRocks init with no arguments", function()
      test_env.run_in_tmp(function(tmpdir)
         local myproject = tmpdir .. "/myproject"
         lfs.mkdir(myproject)
         lfs.chdir(myproject)
         
         assert(run.luarocks("init"))
         if is_win then
            assert.truthy(lfs.attributes(myproject .. "/lua.bat"))
            assert.truthy(lfs.attributes(myproject .. "/luarocks.bat"))
         else
            assert.truthy(lfs.attributes(myproject .. "/lua"))
            assert.truthy(lfs.attributes(myproject .. "/luarocks"))
         end
         assert.truthy(lfs.attributes(myproject .. "/lua_modules"))
         assert.truthy(lfs.attributes(myproject .. "/.luarocks"))
         assert.truthy(lfs.attributes(myproject .. "/.luarocks/config-" .. test_env.lua_version .. ".lua"))
         assert.truthy(lfs.attributes(myproject .. "/.gitignore"))
         assert.truthy(lfs.attributes(myproject .. "/myproject-dev-1.rockspec"))
      end, finally)
   end)
   
   it("LuaRocks init with given arguments", function()
      test_env.run_in_tmp(function(tmpdir)
         local myproject = tmpdir .. "/myproject"
         lfs.mkdir(myproject)
         lfs.chdir(myproject)
         
         assert(run.luarocks("init customname 1.0"))
         assert.truthy(lfs.attributes(myproject .. "/customname-1.0-1.rockspec"))
      end, finally)
   end)
   
   it("LuaRocks init in a git repo", function()
      test_env.run_in_tmp(function(tmpdir)
         local myproject = tmpdir .. "/myproject"
         copy_dir(testing_paths.fixtures_dir .. "/git_repo", myproject)
         lfs.chdir(myproject)
         
         assert(run.luarocks("init"))
         local fd = assert(io.open(myproject .. "/myproject-dev-1.rockspec", "r"))
         local content = assert(fd:read("*a"))
         assert.truthy(content:find("summary = \"Test repo\""))
         assert.truthy(content:find("detailed = .+Test repo.+"))
         assert.truthy(content:find("license = \"MIT\""))
         
         fd = assert(io.open(myproject .. "/.gitignore", "r"))
         content = assert(fd:read("*a"))
         assert.truthy(content:find("/foo"))
         assert.truthy(content:find("/lua"))
         assert.truthy(content:find("/lua_modules"))
      end, finally)
   end)
end)