Skip to contentSkip to conversation

package/luarocks: better choice of modules in generated test

PATCH New Francois Perrad 2 participants 3 messages Mar 31, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 package/luarocks: better choice of modules in generated test

the name derived from package name is not suitable, so, we search in the built modules.

---
 package/luarocks/buildroot.lua | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)
package/luarocks/buildroot.lua +27 -4
index 61e44a867..39f0fe759 100644
@@ -70,6 +70,25 @@ local function has_c_files (rockspec)
    return false
 end
 
+local function get_main_modules (rockspec)
+   local t = {}
+   for name in pairs(rockspec.build.modules or {}) do
+      if not name:match('%.') then
+         t[#t+1] = name
+      end
+   end
+   if #t == 0 then
+      for name in pairs(rockspec.build.modules or {}) do
+         t[#t+1] = name
+      end
+   end
+   if #t == 0 then
+      t[#t+1] = rockspec.package:gsub('%-', '')
+   end
+   table.sort(t)
+   return t
+end
+
 local function get_external_dependencies (rockspec)
    local t = {}
    for k in pairs(rockspec.external_dependencies or {}) do
@@ -251,9 +270,9 @@ end
 
 local function generate_test (rockspec, lcname)
    local ucname = brname(lcname)
-   local modname = rockspec.package:gsub('%-', '')
-   local classname = modname:gsub('%.', '')
+   local classname = rockspec.package:gsub('%-', ''):gsub('%.', '')
    classname = classname:sub(1, 1):upper() .. classname:sub(2)
+   local modnames = get_main_modules(rockspec)
    local fname = 'support/testing/tests/package/test_' .. ucname:lower() .. '.py'
    local f = assert(io.open(fname, 'w'))
    util.printout('write ' .. fname)
@@ -269,7 +288,9 @@ local function generate_test (rockspec, lcname)
    f:write('\n')
    f:write('    def test_run(self):\n')
    f:write('        self.login()\n')
-   f:write('        self.module_test("' .. modname .. '")\n')
+   for i = 1, #modnames do
+      f:write('        self.module_test("' .. modnames[i] .. '")\n')
+   end
    f:write('\n')
    f:write('\n')
    f:write('class TestLuajit' .. classname .. '(TestLuaBase):\n')
@@ -281,7 +302,9 @@ local function generate_test (rockspec, lcname)
    f:write('\n')
    f:write('    def test_run(self):\n')
    f:write('        self.login()\n')
-   f:write('        self.module_test("' .. modname .. '")\n')
+   for i = 1, #modnames do
+      f:write('        self.module_test("' .. modnames[i] .. '")\n')
+   end
    f:close()
 end
 
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 support/testing/tests/package/test_lua*: regeneration

---
 support/testing/tests/package/test_lpeg.py      | 6 ++++--
 support/testing/tests/package/test_lua_curl.py  | 2 ++
 support/testing/tests/package/test_luaossl.py   | 2 ++
 support/testing/tests/package/test_luasocket.py | 4 ++++
 4 files changed, 12 insertions(+), 2 deletions(-)
support/testing/tests/package/test_lpeg.py +4 -2
index e57415735..4e1ee343b 100644
@@ -10,7 +10,8 @@ class TestLuaLPeg(TestLuaBase):
 
     def test_run(self):
         self.login()
-        self.module_test("lpeg", script="print(require[[lpeg]].version())")
+        self.module_test("lpeg")
+        self.module_test("re")
 
 
 class TestLuajitLPeg(TestLuaBase):
@@ -22,4 +23,5 @@ class TestLuajitLPeg(TestLuaBase):
 
     def test_run(self):
         self.login()
-        self.module_test("lpeg", script="print(require[[lpeg]].version())")
+        self.module_test("lpeg")
+        self.module_test("re")
support/testing/tests/package/test_lua_curl.py +2 -0
index 5ee79313f..081303948 100644
@@ -11,6 +11,7 @@ class TestLuaLuacURL(TestLuaBase):
     def test_run(self):
         self.login()
         self.module_test("cURL")
+        self.module_test("lcurl")
 
 
 class TestLuajitLuacURL(TestLuaBase):
@@ -23,3 +24,4 @@ class TestLuajitLuacURL(TestLuaBase):
     def test_run(self):
         self.login()
         self.module_test("cURL")
+        self.module_test("lcurl")
support/testing/tests/package/test_luaossl.py +2 -0
index f6914e054..f9f9ab4ee 100644
@@ -11,6 +11,7 @@ class TestLuaLuaossl(TestLuaBase):
     def test_run(self):
         self.login()
         self.module_test("openssl")
+        self.module_test("_openssl")
 
 
 class TestLuajitLuaossl(TestLuaBase):
@@ -23,3 +24,4 @@ class TestLuajitLuaossl(TestLuaBase):
     def test_run(self):
         self.login()
         self.module_test("openssl")
+        self.module_test("_openssl")
support/testing/tests/package/test_luasocket.py +4 -0
index c2d19d78c..3d21df1de 100644
@@ -10,6 +10,8 @@ class TestLuaLuaSocket(TestLuaBase):
 
     def test_run(self):
         self.login()
+        self.module_test("ltn12")
+        self.module_test("mime")
         self.module_test("socket")
 
 
@@ -22,4 +24,6 @@ class TestLuajitLuaSocket(TestLuaBase):
 
     def test_run(self):
         self.login()
+        self.module_test("ltn12")
+        self.module_test("mime")
         self.module_test("socket")
Signature · 1 line
2.17.1
#2 lore raw

PATCH 1/2 package/luarocks: better choice of modules in generated test

In reply to Francois Perrad
Quoted 7 lines · On Sun, 31 Mar 2019 08:48:44 +0200 Francois Perrad <[email protected]> wrote:

the name derived from package name is not suitable, so, we search in the built modules.

---
 package/luarocks/buildroot.lua | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

Both applied, thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com