CXwudi / comp5903-easy-cucumber

A JVM Cucumber implementation that is easy to use. It is the enhanced "Cucumberized JUnit" of the original version from Alexei https://github.com/alexeikrumshyn/cucumberized-junit
0 stars 0 forks source link

[Bug/Question] Regex matching fails for similar strings #12

Closed saurabhsjoshi closed 2 years ago

saurabhsjoshi commented 2 years ago

Describe the bug or Question In some cases, the regex matching seems to be incorrectly matching step def and string literal in feature file.

(For bug report only) To Reproduce Steps to reproduce the behavior:

  1. Create feature file with following scenario: test.feature

    Feature: Test feature
    
    Scenario: Test scenario
    Given Test given
    When Test when
    And 'Player3' gets 'GOLD' fortune card
    And 'Player3' gets disqualified
    Then Test then
  2. Creat step def file with following definitions: TestDefs.java
    
    package org.joshi.easy.cucumber;

import scs.comp5903.cucumber.model.annotation.JAndStep; import scs.comp5903.cucumber.model.annotation.JGivenStep; import scs.comp5903.cucumber.model.annotation.JThenStep; import scs.comp5903.cucumber.model.annotation.JWhenStep;

public class TestDefs {

@JGivenStep("Test given")
public void given() {}

@JWhenStep("Test when")
public void when() {}

@JThenStep("Test then")
public void then() {}

@JAndStep("{string} gets {string} fortune card")
public void andTest(String player, String card) {}

@JAndStep("{string} is disqualified")
public void disqualified(String player) {}

}


3. Execute using following code
```java
EasyCucumber.build(Paths.get("src/test/resources/test.feature"), TestDefs.class).executeAll();

(If applicable) Stack Trace

logs

scs.comp5903.cucumber.model.exception.EasyCucumberException: EZCU010: Unable to find string literals: disqualified, the string literal should be in double or single quotes. at scs.comp5903.cucumber.builder.JStepParameterExtractor.extractParameterValueAndGetNextIndex(JStepParameterExtractor.java:137) at scs.comp5903.cucumber.builder.JStepParameterExtractor.tryExtractParameters(JStepParameterExtractor.java:69) at scs.comp5903.cucumber.builder.JFeatureBuilder.tryMatchStep(JFeatureBuilder.java:99) at scs.comp5903.cucumber.builder.JFeatureBuilder.mapAllStepsToStepDefMethods(JFeatureBuilder.java:88) at scs.comp5903.cucumber.builder.JFeatureBuilder.build(JFeatureBuilder.java:46) at scs.comp5903.cucumber.EasyCucumber.build(EasyCucumber.java:147) at scs.comp5903.cucumber.EasyCucumber.build(EasyCucumber.java:68) at org.joshi.easy.cucumber.TestRunner.sampleTest(TestRunner.java:71) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727) at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131) at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86) at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103) at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37) at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92) at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86) at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86) at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57) at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54) Process finished with exit code 255

(If applicable) Screenshots If applicable, add screenshots to help explain your problem.

(For bug report only) Expected behavior The regex matching should work as expected and framework should not try to match And 'Player3' gets disqualified with @JAndStep("{string} gets {string} fortune card")

Environment (please complete the following information):

Anything else N/A

CXwudi commented 2 years ago

I see, this should not be traded as hard error but a mismatching. Will be fixed in 0.3.3

CXwudi commented 2 years ago

Meanwhile, the workaround for now is having the different characters in step literals to let the tool distinguish two similar steps.

For example, the "a" in And 'Player3' gets a 'GOLD' fortune card will make the tool not matching And 'Player3' gets disqualified

CXwudi commented 2 years ago

Hi,

could you try https://jitpack.io/#CXwudi/comp5903-easy-cucumber/ee2d3f32a6 and see if it fixes your issue?

then I will release 0.3.3

saurabhsjoshi commented 2 years ago

Hey @CXwudi! I can confirm that comp5903-easy-cucumber:ee2d3f32a6 fixed this issue. Thanks!