...(com.abc.MyOtherProg.Type as java.lang.Class).getDeclaredMethod( "evaluate", {gw.lang.reflect.gs.IExternalSymbolMap} ).invoke( new com.abc.MyOtherProg(), {null})
package aslak
enhancement MyProgEnhancement : gw.lang.reflect.gs.IProgramInstance {function execute() {(typeof this as java.lang.Class).getDeclaredMethod( "evaluate",{gw.lang.reflect.gs.IExternalSymbolMap} ).invoke( this, {null} )
}}
new MyOtherProg().execute()
MyOtherProg.evaluate()
<repositories> <repository> <id>gosu-lang.org-releases</id> <name>Official Gosu website (releases)</name> <url>http://gosu-lang.org/repositories/m2/releases</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.gosu-lang.gosu</groupId> <artifactId>gosu</artifactId> <version>0.10.3</version> <type>pom</type> </dependency> ...
Hi Aslak.Nice to see you providing support for Gosu in Cucumber! You've caught us in the middle of some exciting changes in Gosu.. actually less in the middle and more toward the end. In any respect I can help you get by with the current release of Gosu and then provide some guidance concerning where Gosu is headed and how you can improve support for it in Cucumber.So to answer your questions. Yes, a Gosu Program (.gsp) is the equivalent of a script in dynamic languages. A program may define any number of classes, functions, and free-from statements, or just a simple expression. Programs compile to conventional .class files.As you've discovered Programs aren't intended to be executed from other programs. The original intention for them was to provide an entry point for an application or to exist as a simple script. The idea was that if you needed to nominally execute or chain to other code, it's best to write that code as a class, which is what you've done to work around the problem (for now).You can alternatively execute another program reflectively e.g.,MyProg.gsp...(com.abc.MyOtherProg.Type as java.lang.Class).getDeclaredMethod( "evaluate", {gw.lang.reflect.gs.IExternalSymbolMap} ).invoke( new com.abc.MyOtherProg(), {null})
We'd be glad to assist you in your effort to support Gosu in Cucumber JVM. Just let us know.Cheers.Scott
On Wednesday, March 5, 2014 4:13:19 PM UTC-8, Aslak Hellesøy wrote:Hi everyone,I am the creator of Cucumber and Cucumber-JVM [1]My experience with Gosu is only a few hours - I started implementing cucumber-gosu [2] today so that people can use Cucumber-JVM and write their step definitions [3] in Gosu. Several things are puzzling me.In JavaScript/Ruby/Python you can put your step definitions in several scripts. My understanding is that the equivalent of a script in Gosu is a "Gosu Program" - a .gsp file.Is it possible for a .gsp to run another .gsp in the same JVM? This would be necessary in order to define step defintions in multiple files, something Cucumber users typically do to organise their code.I couldn't figure out to do this, so in my rough prototype I used a class instead, but that seems rather clunky. I'm also not sure what would be the best way to dynamically load many such stepdef classes without knowing their names. Cucumber-JVM scans the filesystem for scripts and loads them. (Cucumber-JVM's Java module uses reflection instead, but let's not go there).Another small inconvenience I ran into was the lack of gosu jar files in the maven repository. I found the gosu repo, but it only has tarballs, so I ended up adding the gosu jars to git - not ideal.I'd love some feedback and pointers about this.Cheers,Aslak
--
You received this message because you are subscribed to a topic in the Google Groups "gosu-lang" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gosu-lang/yMJnzQwuFpo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gosu-lang+...@googlegroups.com.
To post to this group, send email to gosu...@googlegroups.com.
Visit this group at http://groups.google.com/group/gosu-lang.
For more options, visit https://groups.google.com/groups/opt_out.
Now I have a new problem. First, I'm trying to define some global functions (Given, When Then) that the user will call from .gsp scripts to define step definitions. I couldn't figure out how to define a global function though. Is it possible, or can you recommend another Gosu-idiomatic way to do this? It would also be acceptable to have a global object or some easily-imported static methods that could be called.
package aslakclass Stuff {static function Given() {...}static function When() {...}...}
uses aslak.Stuff...Stuff.When()
uses aslak.Stuffextends StuffWhen()
Now I have a new problem. First, I'm trying to define some global functions (Given, When Then) that the user will call from .gsp scripts to define step definitions. I couldn't figure out how to define a global function though. Is it possible, or can you recommend another Gosu-idiomatic way to do this? It would also be acceptable to have a global object or some easily-imported static methods that could be called.Probably your best bet right now is to defined a class with static methods e.g.,Stuff.gspackage aslakclass Stuff {static function Given() {...}static function When() {...}...}The your programs can use Stuff and call static methods e.g.,MyProg.gspuses aslak.Stuff...Stuff.When()Will that suffice?
We have a better way in the up coming release where your program can extend a class and avoid qualifying the function calls:MyProg.gspuses aslak.Stuffextends Stuff
When()
Another benefit of this approach is that the methods in Stuff could be changed to instance methods and state can be maintained with instance fields.
Hope this helps.
Hi everyone,
Gosu support in Cucumber (cucumber-gosu module) is currently broken. The module has been temporarily removed from the cucumber project in Github due to build failures. I'm trying to fix this but have hit a brick wall and I'm seeking your guidance to get it resolved. Details below.
The current cucumber-gosu implementation depends on classes in gw.lang.launch.* that have been removed since gosu-core-1.4. Therefore the solution implemented in a couple of years back is now broken. The cucumber-gosu implementation needs to be refactored to work with the latest gosu core libraries. I'm using gosu-core-1.13.4 for my testing purposes.
|
|
@Override |
|
|
public void loadGlue(Glue glue, List<String> gluePaths) { |
|
|
this.glue = glue; |
|
|
GlueSource source = new GlueSource(); |
|
|
for (String gluePath : gluePaths) { |
|
|
for (Resource glueScript : resourceLoader.resources(gluePath, ".gsp")) { |
|
|
source.addGlueScript(glueScript); |
|
|
} |
|
|
} |
|
|
Gosu gosu = new Gosu(); |
|
|
gosu.start(source.toArgInfo()); |
|
|
} |
var clazz:Class=ReflectUtil.getClass("cucumber.features.MyStepDefinitions").getBackingClass()
((IProgramInstance)(clazz.newInstance())).evaluate(null);
This works fine if I run this on a Gosu Scratchpad (in IntelliJ) but fails with the following exception when executed from the cucumber-gosu library. Based on my investigation it fails to find the above class in the classpath under the _default_ module.
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:46)
Caused by: gw.internal.gosu.parser.RuntimeExceptionWithNoStacktrace: java.lang.ClassNotFoundException: cucumber.features.MyStepDefinitions in module _default_
Caused by: java.lang.ClassNotFoundException: cucumber.features.MyStepDefinitions in module _default_
at gw.internal.gosu.parser.TypeLoaderAccess.getIntrinsicTypeByFullName(TypeLoaderAccess.java:366)
at gw.internal.gosu.parser.TypeLoaderAccess.getByFullName(TypeLoaderAccess.java:959)
at gw.lang.reflect.TypeSystem.getByFullName(TypeSystem.java:154)
at gw.lang.reflect.ReflectUtil.getClass(ReflectUtil.java:156)
at gw.lang.reflect.ReflectUtil.getClassButThrowIfInvalid(ReflectUtil.java:161)
at cucumber.runtime.gosu.GosuBackend.runGlueScript(GosuBackend.java:47) <-- this is where I call ReflectUtil.getClass(…)
at cucumber.runtime.gosu.GosuBackend.loadGlue(GosuBackend.java:42)
at cucumber.runtime.Runtime.<init>(Runtime.java:90)
at cucumber.runtime.Runtime.<init>(Runtime.java:68)
at cucumber.runtime.Runtime.<init>(Runtime.java:64)
at cucumber.api.cli.Main.run(Main.java:35)
at cucumber.api.cli.Main.main(Main.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:46)
--
You received this message because you are subscribed to the Google Groups "gosu-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gosu-lang+unsubscribe@googlegroups.com.
To post to this group, send email to gosu...@googlegroups.com.
Visit this group at https://groups.google.com/group/gosu-lang.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to gosu-lang+...@googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "gosu-lang" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gosu-lang/yMJnzQwuFpo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gosu-lang+unsubscribe@googlegroups.com.
package cucumber.features
uses cucumber.api.junit.Cucumber
uses org.junit.runner.RunWith
/**
* Created by Kaushalya Samarasekera on 14/12/2016.
*/
@RunWith(Cucumber)
class RunCucumber {
}