I need to build a scripting interface for my C# program that does system level testing of embedded firmware.
My application contains libraries to fully interact with
IronRuby is the most powerful for creating domain-specific languages, because it's syntax is much more flexible and forgiving than python's (your users are going to screw the whitespace up and get annoyed by the mandatory () to call methods).
You could write your sample script in IronRuby and it would look like this:
TURN_POWER_ON
TUNE_FREQUENCY frequency
WAIT 5
if GET_FREQUENCY == frequency
REPORT_PASS "Successfully tuned to " + frequency
else
REPORT_FAIL "Failed to tune to " + frequency
end
TURN_POWER_OFF
Here's a sample of a DSL our Testers are currently using to write automated tests against our UI
window = find_window_on_desktop "OurApplication"
logon_button = window.find "Logon"
logon_button.click
list = window.find "ItemList"
list.should have(0).rows
add_button = window.find "Add new item"
add_button.click
list.should have(1).rows
However, as things stand right now IronPython is much more mature and has much better performance than IronRuby, so you may prefer to use that.
I'd strongly recommend going with either IronPython or IronRuby over creating your own custom language... You'll save an unimaginable amount of effort (and bugs)
From the DSL you're going for, I'd recommend to use CUCUMBER with IronRuby.
With Cucumber, testers write tests that look something like that:
Scenario: See all vendors
Given I am logged in as a user in the administrator role
And There are 3 vendors
When I go to the manage vendors page
Then I should see the first 3 vendor names
It is very easy to make this language fit your needs. Just google "Cucumber and IronRuby" and you'll find several guides and blog posts to get you started.
We are using embedded Iron Python for pricing formula in one of our project. This is how a real sample on how it looks like.
E_DOCUMENT_CHECK = DCPAV * ADS_NUM
E_SPECIFIC_TAX = STV
E_RESOURCE_DEV = RDV
E_LP_ISSUANCE = LPIV
E_ANNUAL_FEES = APFCV * SA * SIDES_NUM
E_SERVICE_FEES= MAX(
MINSFV,
E_DOCUMENT_CHECK+E_SPECIFIC_TAX+E_RESOURCE_DEV+E_LP_ISSUANCE+E_ANNUAL_FEES)
TOTAL= E_DOCUMENT_CHECK+E_SPECIFIC_TAX+E_RESOURCE_DEV+E_LP_ISSUANCE+E_ANNUAL_FEES+E_SERVICE_FEES
It is really straightforward to implement. The Max() function for example is just one of the custom C# method that we import to the IronPython engine and it looks natural to use in a configuration settings.