-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do you get test access to privates with the module() function? #60
Comments
I am not sure. I think Tieske will need to comment on this as he added the _TEST system I believe. |
looping in @Tieske |
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 |
Just wrote a quick test setup. For a module exporting is done the other way around, always export, delete when not testing; The module 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 |
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. |
The private example using _TEST uses the method of returning a table of functions to be a module, rather than the module(...,package.seeall) method.
how can I test privates this way? Is it even possible?
The text was updated successfully, but these errors were encountered: