aboutsummaryrefslogtreecommitdiff
path: root/spec/rockspecs_spec.lua
blob: 76b33f656598473fa7ab58a4dc5a112b5f4a397e (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

local rockspecs = require("luarocks.rockspecs")
local cfg = require("luarocks.core.cfg")
local test_env = require("spec.util.test_env")
local lfs = require("lfs")

describe("luarocks.rockspecs", function()

   setup(function()
      cfg.init()
   end)

   it("auto adds a build dependency for non-vendored build types", function()
      local filename = "test-1.0-1.rockspec"
      local rockspec = {
         package = "test",
         source = {
            url = "",
         },
         build = {
            type = "foo"
         },
      }
      local globals = {}
      local quick = true

      local out = rockspecs.from_persisted_table(filename, rockspec, globals, quick)

      assert(rockspec == out)
      assert.same(rockspec.build_dependencies, {
         { name = "luarocks-build-foo", constraints = {} },
      })
   end)

   it("does not add a build dependency for non-vendored build type if it's already ther", function()
      local filename = "test-1.0-1.rockspec"
      local rockspec = {
         package = "test",
         source = {
            url = "",
         },
         build_dependencies = {
            "luarocks-build-cpp >= 1.0",
         },
         build = {
            type = "cpp"
         },
      }
      local globals = {}
      local quick = true

      local out = rockspecs.from_persisted_table(filename, rockspec, globals, quick)

      assert(rockspec == out)

      assert.same(rockspec.build_dependencies, {
         { name = "luarocks-build-cpp", constraints = { { op = ">=", version = { string = "1.0", 1, 0 } } } },
      })
   end)

   it("does not add a build dependency for 'none' build type", function()
      local filename = "test-1.0-1.rockspec"
      local rockspec = {
         package = "test",
         source = {
            url = "",
         },
         build = {
            type = "none"
         },
      }
      local globals = {}
      local quick = true

      local out = rockspecs.from_persisted_table(filename, rockspec, globals, quick)

      assert(rockspec == out)
      assert.same(rockspec.build_dependencies, {})
   end)

   it("does not add a build dependency for 'module' build type", function()
      local filename = "test-1.0-1.rockspec"
      local rockspec = {
         package = "test",
         source = {
            url = "",
         },
         build = {
            type = "none"
         },
      }
      local globals = {}
      local quick = true

      local out = rockspecs.from_persisted_table(filename, rockspec, globals, quick)

      assert(rockspec == out)
      assert.same(rockspec.build_dependencies, {})
   end)

   for d in lfs.dir(test_env.testing_paths.src_dir .. "/luarocks/build") do
      local name = d:match("(.*)%.lua")
      if name then
         it("does not add a build dependency for vendored '" .. name .. "' type", function()
            local filename = "test-1.0-1.rockspec"
            local rockspec = {
               package = "test",
               source = {
                  url = "",
               },
               build = {
                  type = name
               },
            }
            local globals = {}
            local quick = true

            local out = rockspecs.from_persisted_table(filename, rockspec, globals, quick)

            assert(rockspec == out)
            assert.same(rockspec.build_dependencies, {})
         end)
      end
   end

end)