Skip to content
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

Add method prefix and test prefix/suffix options. #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

obszczymucha
Copy link

@obszczymucha obszczymucha commented Jan 2, 2023

This allows specifying the prefix for test and method names, so the tests can be now defined as follows:

function shouldValidateArguments()
...
end

or

function should_validate_arguments()
...
end

If not provided, the behavior is unchanged and it defaults to the current test prefix.

Runner example:

local runner = lu.LuaUnit.new()
runner:setOutputType( "text" )
os.exit( runner:runSuite( "-t", "should" ) )

Or we can do this with objects:

MySpecification = {}

function MySpecification:shouldAddTwoNumbers()
...
end

Runner example:

local runner = lu.LuaUnit.new()
runner:setOutputType( "text" )
os.exit( runner:runSuite( "-T", "Specification", "-m", "should" ) )

@obszczymucha obszczymucha changed the title Add method and test prefix options. Add method prefix and test prefix/suffix options. Jan 2, 2023
@@ -3393,6 +3424,9 @@ end
self.exeRepeat = options.exeRepeat
self.patternIncludeFilter = options.pattern
self.shuffle = options.shuffle
self.methodPrefix = self.methodPrefix or options.methodPrefix
self.testPrefix = self.testPrefix or options.testPrefix
self.testSuffix = self.testSuffix or options.testSuffix

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about that part. The idea normally is that options passed on the command-line should overwrite what you defined in your test runner. This gives a dynamic behavior on the command-line, and I have the feeling that this code does not respect this behavior.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to give an example on how can I set up the options in the test runner?
When I tried doing this:

local runner = lu.LuaUnit.new()
runner:setOutputType( "text" )
os.exit( runner:runSuite( "-p", "somepattern" ) )

and then override it via the command line:

lua my_test.lua -p somenewpattern

It doesn't override it. It still uses the somepattern.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I reviewed the code and indeed, it is imperfect. Setting up the arguments directly in function completely erase the command-line argument parsing.

I am not sure what's the best way to fix this general problem. My idea is that command-line should override function parameters when an option is defined in both places, but for non conflicting options, both should be merged.

@bluebird75
Copy link
Owner

Hi,

Sorry for the delay, I just moved to a new house so things like open source have been left behind.

I like the patch, I need to further review it but it looks great. And with unit-tests, this is exceptional 👍

@obszczymucha
Copy link
Author

Hey. No worries at all! Thanks for responding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants