-
Notifications
You must be signed in to change notification settings - Fork 91
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
Add basic C++ support #43
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.o | ||
tags | ||
test | ||
test++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
UNAME=$(shell uname) | ||
|
||
CCFLAGS=-Wall -Wextra -Wconversion -Wredundant-decls -Wshadow -Wno-unused-parameter -O3 | ||
CC=clang | ||
CXX=clang++ | ||
|
||
all: test | ||
all: test test++ | ||
|
||
remake: clean all | ||
|
||
%.o: %.c ctest.h | ||
%.cpp: %.c | ||
ln -fs $< $@ | ||
|
||
%.c.o: %.c ctest.h | ||
$(CC) $(CCFLAGS) -c -o $@ $< | ||
|
||
test: main.o ctest.h mytests.o | ||
$(CC) $(LDFLAGS) main.o mytests.o -o test | ||
%.cpp.o: %.cpp ctest.h | ||
$(CXX) $(CCFLAGS) -c -o $@ $< | ||
|
||
clean: | ||
rm -f test *.o | ||
test: main.c.o ctest.h mytests.c.o | ||
$(CC) $(LDFLAGS) main.c.o mytests.c.o -o test | ||
|
||
test++: main.cpp.o ctest.h mytests.cpp.o | ||
$(CXX) $(LDFLAGS) main.cpp.o mytests.cpp.o -o test++ | ||
|
||
clean: | ||
rm -f test test++ *.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The handling of the optional setup/teardown functions is the only place where the actual logic must differ between the C and C++ compilation. The problem is that C++ doesn't support tentative definitions the way that C does, which we currently rely on. Having 2 separate approaches to solve the same problem isn't ideal, so it would be nice if we could come up with an approach that both the C and C++ could share.
One potential option is to use a hashtable to store the setup and teardown function pointers, keyed by suite name. Then we could populate this hashtable using
__attribute__ ((constructor))
functions that we would install as part of theCTEST_SETUP()
/CTEST_TEARDOWN
macros. Here is an example implementation (leaving out the hashtable implementation for brevity):And here is what the main loop might look like, with relevant changes emphasized with
>>
s.This would add some runtime overhead, but the hashtable operations are O(1) so it shouldn't be too bad. It also has the benefit of being less clever and easier to reason about than the C tentative definition approach as well as the C++ template specialization approach.