Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMock generates invalid C for headers with dashes in the name #3

Closed
malsyned opened this issue Jul 28, 2012 · 4 comments
Closed

CMock generates invalid C for headers with dashes in the name #3

malsyned opened this issue Jul 28, 2012 · 4 comments

Comments

@malsyned
Copy link

@malsyned malsyned commented Jul 28, 2012

When I gave CMock a header file named cmock-bug.h with the contents:

#ifndef CMOCK_BUG_H
#define CMOCK_BUG_H

void cmock_bug(void);

#endif /* !CMOCK_BUG_H */

It created this Mockcmock-bug.h:

#ifndef _MOCKCMOCK-BUG_H
#define _MOCKCMOCK-BUG_H

#include "cmock-bug.h"

void Mockcmock-bug_Init(void);
void Mockcmock-bug_Destroy(void);
void Mockcmock-bug_Verify(void);

#define cmock_bug_Expect() cmock_bug_CMockExpect(__LINE__)
void cmock_bug_CMockExpect(UNITY_LINE_TYPE cmock_line);

#endif

This mock header file won't compile because of the dashes in the guard macro and function names.

Dashes are pretty common in C file names, particularly in GNU and Gnome source code. This seems like a use case CMock would want to support.

@malsyned
Copy link
Author

@malsyned malsyned commented Jul 28, 2012

Actually, it looks like cmock requires the header file name to be a valid C identifier.

@barneywilliams
Copy link
Member

@barneywilliams barneywilliams commented Jul 29, 2012

I believe the issue is that the regular expression we are using simply isn't allowing '-' as a valid header file name, though it definitely should.

We will add this to the list.

Thanks,
Greg

@malsyned
Copy link
Author

@malsyned malsyned commented Jul 29, 2012

Here's a patch that fixes the issue for me:

http://malsyned.net/files/patches/cmock-sanitize-identifiers.patch

@sw17ch
Copy link
Contributor

@sw17ch sw17ch commented Oct 17, 2012

@malsyned Could you recreate this patch as a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.