Skip to content

Error parsing libcurl header #502

@intael

Description

@intael

I'm trying to mock libcurl using the following command:

/Users/u/.rbenv/shims/ruby /Users/u/repositories/rofi-reddit/lib/CMock/lib/cmock.rb -o/Users/u/repositories/rofi-reddit/cmock_curl.yaml /Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/include/curl/curl.h

The config (cmock_curl.yaml ) looks like this:

:cmock:
  :verbosity: 3
  :subdir: curl
  :mock_path: ../tests
  :mock_prefix: mock_
  :plugins:
    - :callback
    - :ignore
  :attributes:
    - CURL_EXTERN
    - CURL_DEPRECATED

I'm getting the following error:

/Users/u/.rbenv/shims/ruby /Users/u/repositories/rofi-reddit/lib/CMock/lib/cmock.rb -o/Users/u/repositories/rofi-reddit/cmock_curl.yaml /Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/include/curl/curl.h
/Users/u/repositories/rofi-reddit/lib/CMock/lib/cmock_header_parser.rb:600:in `parse_declaration': Failed Parsing Declaration Prototype! (RuntimeError)
  declaration: 'CURL_EXTERN CURLFORMcode CURL_DEPRECATED(7.56.0, "Use curl_mime_init()")curl_formadd(struct curl_httppost **httppost, struct curl_httppost **last_post, ...)'
  modifier: ''
  return: {:type => '', :name => 'cmock_to_return', :str => ' cmock_to_return', :void? => false, :ptr? => false, :const? => false, :const_ptr? => false}
  function: ')curl_formadd'
  args: [
    {:ptr? => true, :const? => false, :const_ptr? => false, :name => 'httppost', :type => 'struct curl_httppost**'}
    {:ptr? => true, :const? => false, :const_ptr? => false, :name => 'last_post', :type => 'struct curl_httppost**'}
  ]

	from /Users/u/repositories/rofi-reddit/lib/CMock/lib/cmock_header_parser.rb:46:in `block in parse'
	from /Users/u/repositories/rofi-reddit/lib/CMock/lib/cmock_header_parser.rb:45:in `map'
	from /Users/u/repositories/rofi-reddit/lib/CMock/lib/cmock_header_parser.rb:45:in `parse'
	from /Users/u/repositories/rofi-reddit/lib/CMock/lib/cmock.rb:50:in `generate_mock'
	from /Users/u/repositories/rofi-reddit/lib/CMock/lib/cmock.rb:34:in `block in setup_mocks'
	from /Users/u/repositories/rofi-reddit/lib/CMock/lib/cmock.rb:33:in `each'
	from /Users/u/repositories/rofi-reddit/lib/CMock/lib/cmock.rb:33:in `setup_mocks'
	from /Users/u/repositories/rofi-reddit/lib/CMock/lib/cmock.rb:125:in `<main>'

This is how that function definition looks like in curl.h:

CURL_EXTERN CURLFORMcode CURL_DEPRECATED(7.56.0, "Use curl_mime_init()")
curl_formadd(struct curl_httppost **httppost,
             struct curl_httppost **last_post,
             ...);

Looking at the error and what CMock reports as the function (function: ')curl_formadd'), my guess is that CMock is stripping newlines and this results in the CURL_DEPRECATED macro and the function name ending up merged. CMock's regex to capture the function gets confused and results in this.

I have tried several combinations of :strippables:, but none seems to do the trick. I'm using CMock at the v2.6.0 tag and ruby 2.7.7. Any ideas? Has anyone tried mocking libcurl at all?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions