ThrowTheSwitch / Ceedling

Ruby-based unit testing and build system for C projects
http://throwtheswitch.org
Other
569 stars 240 forks source link

Having trouble using plugins like beep and command_hooks #761

Closed jyc-biz closed 1 year ago

jyc-biz commented 1 year ago

Hey all,

I am trying to experiment with Ceedling's plugins.

:tools:
  :beep_on_done: :bell
  :post_test:
    - :executable: echo
      :arguments:
        - Test done!

However, I get the following error when I call ceedling:

Traceback (most recent call last):
        10: from /usr/local/bin/ceedling:23:in `<main>'
         9: from /usr/local/bin/ceedling:23:in `load'
         8: from /var/lib/gems/2.7.0/gems/ceedling-0.31.1/bin/ceedling:329:in `<top (required)>'
         7: from /var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling.rb:66:in `load_project'
         6: from /var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling.rb:66:in `load'
         5: from /var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/rakefile.rb:47:in `<top (required)>'
         4: from /var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/setupinator.rb:29:in `do_setup'
         3: from /var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/configurator.rb:132:in `tools_setup'
         2: from /var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/configurator.rb:132:in `each_key'
         1: from /var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/configurator.rb:136:in `block in tools_setup'
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/configurator.rb:136:in `[]': no implicit conversion of Symbol into Integer (TypeError)

After looking around online, I found #459 and this separate Google Groups thread that appear to discuss similar issues. My understanding is that specifying :tools: somehow overrides the default :environment:? Therefore, I should re-specify :environment: as below so that the current path is added back for Ceedling to find the necessary tools?

:environment:  
  :paths:  
     - "#{ENV['PATH']}"

In addition to specifying :environment:, I also have the following in project.yml.

:plugins:
  :load_paths:
    - "#{Ceedling.load_path}"
  :enabled:
    - stdout_pretty_tests_report
    - module_generator
    - gcov
    - command_hooks #seems required for command_hooks to be active
    - beep #seems required for beep to be active

However, this now generates the error:

Traceback (most recent call last):
        9: from /usr/local/bin/ceedling:23:in `<main>'
        8: from /usr/local/bin/ceedling:23:in `load'
        7: from /var/lib/gems/2.7.0/gems/ceedling-0.31.1/bin/ceedling:329:in `<top (required)>'
        6: from /var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling.rb:66:in `load_project'
        5: from /var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling.rb:66:in `load'
        4: from /var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/rakefile.rb:47:in `<top (required)>'
        3: from /var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/setupinator.rb:28:in `do_setup'
        2: from /var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/configurator.rb:232:in `eval_environment_variables'
        1: from /var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/configurator.rb:232:in `each'
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/configurator.rb:233:in `block in eval_environment_variables': undefined method `keys' for [:paths, ["\\#{ENV['PATH']}"]]:Array (NoMethodError) 

Seems like there is more that needs to be specified? Please correct any misunderstandings and thank you in advance for your time!

deltalejo commented 1 year ago

Hi @jyc-biz! I think the issue you are experiencing has nothing to do with the environment but instead with a probably broken/missing feature of Ceedling as you already found on #459. Can you try with the following :tools section and see if that works? You need to run Ceedling with more verbosity so the echoed test can be seen. e.g. ceedling verbosity[4] test.

:tools:
  :post_test:
    :executable: echo
    :arguments:
      - Test done!

I've removed the :beep_on_done tool because that does not conform to the Ceedling standard tool definition so it complains when trying to load that tool. That is the reason you are seeing the no implicit conversion of Symbol into Integer (TypeError) error. Also, the :post_test tool is specified as a hash and not as an array, because despite command_hooks plugin supporting an array of tools, Ceedling does not support that when loading the project configuration, so it complains when trying to do so and will lead also to the same error mentioned above.

jyc-biz commented 1 year ago

Hey @deltalejo,

Thank you so much for clarifying! You are right, I removed the :environment: edits and it is still working fine. Turns out the higher verbosity is needed for echo to print out the text (i.e., ceedling verbosity[4] test).

Is the plan to keep it this way? I noticed the higher verbosity also generated more messages while Ceedling runs, which makes the terminal a bit confusing to follow (that said I'm fine with that if that's the case).

By the way I also tried the pre_build command_hooks to run a Python script that I have. Seems like that is working fine as well.

Thanks again for your help!

jyc-biz commented 1 year ago

@deltalejo, I noticed that with pre/post_build command_hooks even commands like ceedling version would cause the hooks to be executed. Please let me know if this is expected behavior/I should open a separate issue.

Thanks!

deltalejo commented 1 year ago

@jyc-biz - Regarding the verbosity, I think the command_hooks plugin could be modified so it prints the command output directly instead of relaying on Ceedling's helper functions that do so taking into account the verbosity level.

deltalejo commented 1 year ago

@jyc-biz, It is expected behavior that the pre/post_build hooks are called in that case. There is a doc about plugins that can give you an idea about when each hook is called, you can refer to the pre_build and post_build section. The doc contains some technical stuff that you can ignore if it is not of your concern.

jyc-biz commented 1 year ago

Sounds great, thanks again for the clarifications!