Cucumber, Wire and Gherkin parser

292 views
Skip to first unread message

Massimo Manca

unread,
May 9, 2012, 9:00:27 AM5/9/12
to cu...@googlegroups.com
Hi Aslak,
excuse me if the questions should be not perfect, I am not a compiler
expert (also I studied computer science but was a long time ago),
normally I develop embedded software using C and C++.

I am interested about C and C++ behavior driven development both at
simulator level then at real hardware level. Il like a lot the Gherkin
syntax and Cucumber as a tool to drive the development.

I understand that Cucumber may be extended using the Wire protocol and
this may be the best way to follow but for my situation should be better
to integrate a Gherkin parser to a different environment so:
- I understand that you implemented the Gherkin parser in Ragel so it
should be portable to generate C or C++ source code from a .rl file; I
found in github cucumber/gherkin/ragel these 2 files:
lexer.c.rl.erb
lexer_common.rl.erb

but seems to me that the first is needed for Ruby and is not ok for C
and in the second there are a lot of reference to @i18n that I supposed
is the mechanism you used to support writing in stories and scenarios in
many different languages so I think there should be one or more files to
define the dictionaries.

Have I missed something or don't you published the Gherkin "Ragel source
code"?
Do you think there is a better way to achieve my goal?

Best regards,

Massimo

Aslak Hellesøy

unread,
May 9, 2012, 10:52:04 AM5/9/12
to cu...@googlegroups.com


On Wednesday, May 9, 2012 8:00:27 AM UTC-5, massimo.manca wrote:
Hi Aslak,

I'm assuming you're also interested in answers from other people than me...
 
excuse me if the questions should be not perfect, I am not a compiler
expert (also I studied computer science but was a long time ago),
normally I develop embedded software using C and C++.

I am interested about C and C++ behavior driven development both at
simulator level then at real hardware level. Il like a lot the Gherkin
syntax and Cucumber as a tool to drive the development.

I understand that Cucumber may be extended using the Wire protocol and
this may be the best way to follow but for my situation should be better
to integrate a Gherkin parser to a different environment so:
- I understand that you implemented the Gherkin parser in Ragel so it
should be portable to generate C or C++ source code from a .rl file; I
found in github cucumber/gherkin/ragel these 2 files:
lexer.c.rl.erb
lexer_common.rl.erb

but seems to me that the first is needed for Ruby and is not ok for C
and in the second there are a lot of reference to @i18n that I supposed
is the mechanism you used to support writing in stories and scenarios in
many different languages so I think there should be one or more files to
define the dictionaries.


The .erb files are processed by ERB (a templating engine) and builds about 40 .rl files, one for each language defined in i18n.yml. Then each of these generated .rl files are processed by Ragel to produce lexers in C/Ruby, Java and JavaScript. 
 
Have I missed something or don't you published the Gherkin "Ragel source
code"?

The build system generates .rl from .rl.erb and .java/.c/.js/.rb from .rl. The generated files are not committed to git, but packaged in the released artifacts.

The C implementation is not standalone C - it depends on the Ruby runtime, mostly for Regexp and String manipulation, but also in order to invoke ruby methods to fire off lexer events.

We could have built a "pure" C implementation, and this was discussed when Benno Rice started on a Python implementation. It still hasn't happened though. See https://github.com/jeamland/gherkin/commit/67e7274d5d24af090f91c30b44c84361e89803a1#all_commit_comments


Do you think there is a better way to achieve my goal?


I'm not sure I understand what your goal is. It sounds like you want to run the gherkin parser on an embedded device, but I'm not sure what you expect to achieve by this.

Do you want to use cucumber to test a program running on an embedded device? Have you considered using CukeBins? If you do, cucumber, gherkin and your .feature files would be on one machine and your device would run the embedded software + the cukebins C++ server and your C++ step definitions.

Aslak
 
Best regards,

Massimo

Massimo Manca

unread,
May 9, 2012, 2:38:00 PM5/9/12
to cu...@googlegroups.com
Actually I have a bigger vision that I have no much time to implement that is: using Cucumber interfaced to an hardware test fixture to drive real i/o to perform acceptance tests with real hardware and the complete embedded application running on the real hardware.

The same .feature files may be used to make acceptance tests during all the development from the beginning mocking the hardware and the missing software modules/classes/functions (if the application is written in C or C++). In this situation it may be used with a microcontroller software simulator running on the same PC or with a reduced hardware (just to execute the application on the real microcontroller) and extensive use of mocks.

At the moment I should be happy to realize the simplest part with the simulator or the reduced hardware may be interfaced with a serial or USB connection.


It sounds like you want to run the gherkin parser on an embedded device, but I'm not sure what you expect to achieve by this.
No, I would execute it on a PC; I am thinking about the parser because I already have an application that I wrote and so I know very well that may be simple to interface for me then making a C-Cukebin app.


Do you want to use cucumber to test a program running on an embedded device? Have you considered using CukeBins? If you do, cucumber, gherkin and your .feature files would be on one machine and your device would run the embedded software + the cukebins C++ server and your C++ step definitions.
Yes, this should be the most comfortable solution but I need a C Cukebin because for a lot of microcontrollers there isn't a C++ compiler because their resources are very limited. For the bigger ones should be ok because I already use C++ on them.
So I would understand if I need more time to develop a C-cukebin interfacing it to Cucumber via Wire protocol or to use a Gherkin C/C++ parser embedded on my MicroMonitor application to made up a simpler runner.

Aslak
 
Best regards,

Massimo

-- There are two rules:
 
1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows people to filter messages.
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
 
You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en

aslak hellesoy

unread,
May 9, 2012, 2:53:25 PM5/9/12
to cu...@googlegroups.com
I'm sorry, but I still don't understand what you expect to achieve by
running a Gherkin C/C++ parser embedded in your device. All gherkin
does is to parse .feature files and fire off events (to Cucumber,
which is written in Ruby - and more recently also in Java). Gherkin is
similar to an XML SAX parser. Nothing more.

Gherkin doesn't _execute_ your features. It just parses them. Cucumber
executes them, by running your step definitions and reporting the
results.

The wire protocol allows Cucumber to talk to an external process over
TCP. It asks the external process for step definitions and also asks
it to execute those step definitions and report the results back to
Cucumber.

It sounds like what you need is a wire protocol implementation in C
that would run on your device.

This has nothing to do with Gherkin.

Aslak

Massimo Manca

unread,
May 9, 2012, 7:01:27 PM5/9/12
to cu...@googlegroups.com
Il 09/05/2012 20:53, aslak hellesoy ha scritto:
> On Wed, May 9, 2012 at 1:38 PM, Massimo Manca
> <massimo....@gmail.com> wrote:
Yes, I understand this.
>
> The wire protocol allows Cucumber to talk to an external process over
> TCP. It asks the external process for step definitions and also asks
> it to execute those step definitions and report the results back to
> Cucumber.
>
> It sounds like what you need is a wire protocol implementation in C
> that would run on your device.
Yes, this is the 1st idea I had also if I should route the Wire
connection on a serial or USB or JTAG interface.
>
> This has nothing to do with Gherkin.
Yes, of course. What I tried to say is that I already have a test
application running on a PC that controls/test the application on the
embedded board but with a less flexible approach then I could implement
using Cucumber/gherkin syntax. So I would understand if I need less time
to interface Cucumber to my embedded board realizing a Wire protocol
implementation running on my embedded board and communicating using Wire
(redirected on a serial interface) or implementing a Gherkin parser and
put it on my existing PC application and using its protocol instead Wire
to communicate with the embedded board.
Reply all
Reply to author
Forward
0 new messages