Jump to content

[Resolved] LuaUnit : doesn't work


C0b0ll

Recommended Posts

Posted (edited)

Hi,

Lua and MTA are new for me and I tried some peace of code. It is very powerful and particularly the unit testing.

I read and tried the tutorial on UnitTesting (http://lua-users.org/wiki/UnitTesting) :

-- Some super function to test 
function my_super_function( arg1, arg2 ) return arg1 + arg2 end 
  
-- Unit testing starts 
require('luaunit') 
  
TestMyStuff = {} --class 
    function TestMyStuff:testWithNumbers() 
        a = 1 
        b = 2 
        result = my_super_function( a, b ) 
        assertEquals( type(result), 'number' ) 
        assertEquals( result, 3 ) 
    end 
  
    function TestMyStuff:testWithRealNumbers() 
        a = 1.1 
        b = 2.2 
        result = my_super_function( a, b ) 
        assertEquals( type(result), 'number' ) 
        -- I would like the result to be always rounded to an integer 
        -- but it won't work with my simple implementation 
        -- thus, the test will fail 
        assertEquals( result, 3 ) 
    end 
  
-- class TestMyStuff 
  
luaUnit:run() 

When I execute this code, the "compilator" (i'm using SciTO editor) says me :

> >lua -e "io.stdout:setvbuf 'no'" "aaa.lua"

lua: aaa.lua:29: attempt to index global 'luaUnit' (a nil value)

stack traceback:

aaa.lua:29: in main chunk

[C]: ?

>Exit code: 1

What can I do to fix that problem ?

Thanks a lot !

Edited by Guest
Posted

As far as I know, MTA blocks 3rd party Lua libraries for security reasons, so require will not load any lib.

Posted

There is no need for it. If you really need one then you'll have to write it yourself.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...