Extending C# .NET application - build a custom scripting language or not?

后端 未结 9 1272
情书的邮戳
情书的邮戳 2020-12-31 10:08

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

9条回答
  •  自闭症患者
    2020-12-31 10:39

    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)

提交回复
热议问题