Giter VIP home page Giter VIP logo

Comments (5)

DorianGray avatar DorianGray commented on May 18, 2024

I am not sure. I think Tieske will need to comment on this as he added the _TEST system I believe.

from busted.

ajacksified avatar ajacksified commented on May 18, 2024

looping in @Tieske

from busted.

Tieske avatar Tieske commented on May 18, 2024

will have a look at it, currently travelling and no test system available. Might be a couple of days.

@karlp redesign your modules anyway, as module() has been deprecated in 5.2

from busted.

Tieske avatar Tieske commented on May 18, 2024

Just wrote a quick test setup. For a module exporting is done the other way around, always export, delete when not testing;

The module newmod.lua:

module ("newmod", package.seeall)
local privatef = function()
    return 1
end
local list = { "hello", "world" }
publicf = function()
    return privatef() + 1
end
-- export private elements for test purposes
-- in module case revert export:
-- 1) always create test table
test = {
    _privatef = privatef,
    _list = list,
}
-- 2) now remove it when not being tested
if not _TEST then test = nil end

and the testcode;

describe("Testing a module defined using a module keyword", function()
    setup(function()
        require("newmod")
    end)
    it("tests the public function", function()
        assert.is.equal(newmod.publicf(), 2)
    end)
    it("tests the private function", function()
        assert.is.equal(newmod.test._privatef(), 1)
    end)
end)

But be aware; it's intended to test private functions, but due to its nature it works on everything that is passed by reference (functions, tables, etc. but not on numbers or strings, which are passed by value)

HTH

from busted.

karlp avatar karlp commented on May 18, 2024

Will have a play with that tomorrow. I can't find anything clear about 5.1 to 5.2 migration, so I can only copy the vast amounts of 5.1 code out there that uses module(), sorry.

from busted.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.