diff mbox series

[next/testing,Lua,modules,01/11] luarocks: add generation of test

Message ID 20190219154311.22173-1-francois.perrad@gadz.org
State Accepted
Headers show
Series [next/testing,Lua,modules,01/11] luarocks: add generation of test | expand

Commit Message

Francois Perrad Feb. 19, 2019, 3:43 p.m. UTC
Signed-off-by: Francois Perrad <francois.perrad@gadz.org>
---
 package/luarocks/buildroot.lua | 60 ++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

Comments

Thomas Petazzoni March 28, 2019, 4:22 p.m. UTC | #1
Hello François,

On Tue, 19 Feb 2019 16:43:01 +0100
Francois Perrad <fperrad@gmail.com> wrote:

> Signed-off-by: Francois Perrad <francois.perrad@gadz.org>
> ---
>  package/luarocks/buildroot.lua | 60 ++++++++++++++++++++++++++++++++++
>  1 file changed, 60 insertions(+)

I have applied this entire series, thanks! It's going in the good
direction, but I found some odd things.

The lpeg test looks like this:

+        self.module_test("lpeg", script="print(require[[lpeg]].version())")

which clearly cannot have been generated by the Luarocks "buildroot"
script, which does only:

+   f:write('        self.module_test("' .. modname .. '")\n')

Also, I've used "lpeg-upgrade" and "rings-upgrade" as tests, and
noticed some differences:

-        self.module_test("lpeg", script="print(require[[lpeg]].version())")
+        self.module_test("LPeg")

So we have the difference I explained above + a difference in the
casing of the module.

We have the same casing difference with rings:

-        self.module_test("rings")
+        self.module_test("Rings")

Is this expected ?

Best regards,

Thomas
Francois Perrad March 28, 2019, 5:13 p.m. UTC | #2
Le jeu. 28 mars 2019 à 17:22, Thomas Petazzoni <thomas.petazzoni@bootlin.com>
a écrit :

> Hello François,
>
> On Tue, 19 Feb 2019 16:43:01 +0100
> Francois Perrad <fperrad@gmail.com> wrote:
>
> > Signed-off-by: Francois Perrad <francois.perrad@gadz.org>
> > ---
> >  package/luarocks/buildroot.lua | 60 ++++++++++++++++++++++++++++++++++
> >  1 file changed, 60 insertions(+)
>
> I have applied this entire series, thanks! It's going in the good
> direction, but I found some odd things.
>
> The lpeg test looks like this:
>
> +        self.module_test("lpeg",
> script="print(require[[lpeg]].version())")
>
> which clearly cannot have been generated by the Luarocks "buildroot"
> script, which does only:
>
> +   f:write('        self.module_test("' .. modname .. '")\n')
>
> Also, I've used "lpeg-upgrade" and "rings-upgrade" as tests, and
> noticed some differences:
>
> -        self.module_test("lpeg",
> script="print(require[[lpeg]].version())")
> +        self.module_test("LPeg")
>
> So we have the difference I explained above + a difference in the
> casing of the module.
>
> We have the same casing difference with rings:
>
> -        self.module_test("rings")
> +        self.module_test("Rings")
>
> Is this expected ?
>

Yes, more or less.

The lua ecosystem has no common policy about naming, etc...
So, a generated stuff sometime needs a manual editing.

François


> Best regards,
>
> Thomas
> --
> Thomas Petazzoni, CTO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
>
<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le jeu. 28 mars 2019 à 17:22, Thomas Petazzoni &lt;<a href="mailto:thomas.petazzoni@bootlin.com">thomas.petazzoni@bootlin.com</a>&gt; a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello François,<br>
<br>
On Tue, 19 Feb 2019 16:43:01 +0100<br>
Francois Perrad &lt;<a href="mailto:fperrad@gmail.com" target="_blank">fperrad@gmail.com</a>&gt; wrote:<br>
<br>
&gt; Signed-off-by: Francois Perrad &lt;<a href="mailto:francois.perrad@gadz.org" target="_blank">francois.perrad@gadz.org</a>&gt;<br>
&gt; ---<br>
&gt;  package/luarocks/buildroot.lua | 60 ++++++++++++++++++++++++++++++++++<br>
&gt;  1 file changed, 60 insertions(+)<br>
<br>
I have applied this entire series, thanks! It&#39;s going in the good<br>
direction, but I found some odd things.<br>
<br>
The lpeg test looks like this:<br>
<br>
+        self.module_test(&quot;lpeg&quot;, script=&quot;print(require[[lpeg]].version())&quot;)<br>
<br>
which clearly cannot have been generated by the Luarocks &quot;buildroot&quot;<br>
script, which does only:<br>
<br>
+   f:write(&#39;        self.module_test(&quot;&#39; .. modname .. &#39;&quot;)\n&#39;)<br>
<br>
Also, I&#39;ve used &quot;lpeg-upgrade&quot; and &quot;rings-upgrade&quot; as tests, and<br>
noticed some differences:<br>
<br>
-        self.module_test(&quot;lpeg&quot;, script=&quot;print(require[[lpeg]].version())&quot;)<br>
+        self.module_test(&quot;LPeg&quot;)<br>
<br>
So we have the difference I explained above + a difference in the<br>
casing of the module.<br>
<br>
We have the same casing difference with rings:<br>
<br>
-        self.module_test(&quot;rings&quot;)<br>
+        self.module_test(&quot;Rings&quot;)<br>
<br>
Is this expected ?<br></blockquote><div><br></div><div>Yes, more or less.</div><div><br></div><div>The lua ecosystem has no common policy about naming, etc...</div><div>So, a generated stuff sometime needs a manual editing.<br></div><div> </div><div>François<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Best regards,<br>
<br>
Thomas<br>
-- <br>
Thomas Petazzoni, CTO, Bootlin<br>
Embedded Linux and Kernel engineering<br>
<a href="https://bootlin.com" rel="noreferrer" target="_blank">https://bootlin.com</a><br>
_______________________________________________<br>
buildroot mailing list<br>
<a href="mailto:buildroot@busybox.net" target="_blank">buildroot@busybox.net</a><br>
<a href="http://lists.busybox.net/mailman/listinfo/buildroot" rel="noreferrer" target="_blank">http://lists.busybox.net/mailman/listinfo/buildroot</a><br>
</blockquote></div></div>
Thomas Petazzoni March 28, 2019, 5:22 p.m. UTC | #3
On Thu, 28 Mar 2019 18:13:05 +0100
François Perrad <francois.perrad@gadz.org> wrote:

> > Is this expected ?
> >  
> 
> Yes, more or less.
> 
> The lua ecosystem has no common policy about naming, etc...
> So, a generated stuff sometime needs a manual editing.

So for lpeg you really a special .module_test() call ?

Why is the "rings" test case not matching the output of "make
rings-upgrade" ?

Thanks,

Thomas
diff mbox series

Patch

diff --git a/package/luarocks/buildroot.lua b/package/luarocks/buildroot.lua
index 4be5fbd7c..61e44a867 100644
--- a/package/luarocks/buildroot.lua
+++ b/package/luarocks/buildroot.lua
@@ -49,6 +49,27 @@  local function wrap (txt, max)
    return lines
 end
 
+local function has_c_files (rockspec)
+   for _, mod in pairs(rockspec.build.modules or {}) do
+      if type(mod) == 'string' then
+         if mod:match'%.c$' then
+            return true
+         end
+      elseif type(mod) == 'table' then
+         local sources = mod.sources
+         if type(sources) == 'string' and sources:match'%.c$' then
+            return true
+         end
+         for _, src in ipairs(sources or mod) do
+            if src:match'%.c$' then
+               return true
+            end
+         end
+      end
+   end
+   return false
+end
+
 local function get_external_dependencies (rockspec)
    local t = {}
    for k in pairs(rockspec.external_dependencies or {}) do
@@ -228,6 +249,42 @@  local function generate_hash (rockspec, lcname, rock_file, licenses, digest)
    f:close()
 end
 
+local function generate_test (rockspec, lcname)
+   local ucname = brname(lcname)
+   local modname = rockspec.package:gsub('%-', '')
+   local classname = modname:gsub('%.', '')
+   classname = classname:sub(1, 1):upper() .. classname:sub(2)
+   local fname = 'support/testing/tests/package/test_' .. ucname:lower() .. '.py'
+   local f = assert(io.open(fname, 'w'))
+   util.printout('write ' .. fname)
+   f:write('from tests.package.test_lua import TestLuaBase\n')
+   f:write('\n')
+   f:write('\n')
+   f:write('class TestLua' .. classname .. '(TestLuaBase):\n')
+   f:write('    config = TestLuaBase.config + \\\n')
+   f:write('        """\n')
+   f:write('        BR2_PACKAGE_LUA=y\n')
+   f:write('        BR2_PACKAGE_' .. ucname .. '=y\n')
+   f:write('        """\n')
+   f:write('\n')
+   f:write('    def test_run(self):\n')
+   f:write('        self.login()\n')
+   f:write('        self.module_test("' .. modname .. '")\n')
+   f:write('\n')
+   f:write('\n')
+   f:write('class TestLuajit' .. classname .. '(TestLuaBase):\n')
+   f:write('    config = TestLuaBase.config + \\\n')
+   f:write('        """\n')
+   f:write('        BR2_PACKAGE_LUAJIT=y\n')
+   f:write('        BR2_PACKAGE_' .. ucname .. '=y\n')
+   f:write('        """\n')
+   f:write('\n')
+   f:write('    def test_run(self):\n')
+   f:write('        self.login()\n')
+   f:write('        self.module_test("' .. modname .. '")\n')
+   f:close()
+end
+
 --- Driver function for the "buildroot" command.
 -- @param rockname string: the name of a rock to be fetched and unpacked.
 -- @param brname string: the name used by Buildroot (optional)
@@ -319,6 +376,9 @@  function buildroot.command(flags, rockname, fsname)
    generate_config(rockspec, fsname:lower())
    generate_mk(rockspec, fsname:lower(), licenses)
    generate_hash(rockspec, fsname:lower(), rock_file, licenses, digest)
+   if has_c_files(rockspec) then
+      generate_test(rockspec, fsname:lower())
+   end
 
    return true
 end