-
Notifications
You must be signed in to change notification settings - Fork 11
Conversation
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.
Looks great overall, excited to see tests! One minor comment.
src/Makefile
Outdated
$(CPP_NETLIB_DIR) $(YAML_CPP_DIR) | ||
git submodule deinit --all | ||
$(RM) -r init-submodules build-cpp-netlib build-yaml-cpp | ||
git submodule deinit -f $(CPP_NETLIB_DIR) && \ |
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.
Do these commands need to be chained together? If so, can we indent the second line? Same elsewhere.
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.
I edited the existing Makefile, so have kept the same format.
I have updated the indents in the new Makefile though. PTAL.
Just providing some context around an offline conversation. Igor confirmed the issues with the Makefile on xenial so he is going to work on fixing up the Makefile issues in a separate pull request, and then we'll rebase your changes so that they can focus on the unit test functionality. |
Update the Makefile to load specific submodules.
Also add a Makefile that is easy to extend as we add tests for the remaining code. Only the SRCS needs to be extended in most cases.
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.
LGTM
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.
A preliminary review.
test/Makefile
Outdated
CPPFLAGS+=-isystem $(GTEST_DIR)/include | ||
CXXFLAGS=-std=c++11 -g -pthread | ||
|
||
# Where to find user code. |
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.
s/user code
/code under test
/
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.
Done
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.
Done
src/Makefile
Outdated
@@ -123,15 +123,14 @@ clean: | |||
$(RM) metadatad $(OBJS) | |||
|
|||
purge: clean | |||
$(RM) -r init-submodules build-cpp-netlib build-yaml-cpp \ | |||
$(CPP_NETLIB_DIR) $(YAML_CPP_DIR) | |||
git submodule deinit --all |
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.
I'm confused. Is this just do we don't touch the googletest
submodule during regular builds?
src/Makefile
Outdated
git submodule deinit --all | ||
$(RM) -r init-submodules build-cpp-netlib build-yaml-cpp | ||
git submodule deinit -f $(CPP_NETLIB_DIR) && \ | ||
git submodule deinit -f $(YAML_CPP_DIR) |
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.
Just list both of them on the same line:
git submodule deinit -f $(CPP_NETLIB_DIR) $(YAML_CPP_DIR)
src/Makefile
Outdated
touch init-submodules | ||
git submodule update --init $(CPP_NETLIB_DIR) && \ | ||
git submodule update --init $(YAML_CPP_DIR) | ||
touch ../init-submodules |
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.
Careful! init-submodules
is an actual file target. You can't just move it to the parent directory.
src/Makefile
Outdated
git submodule init && \ | ||
git submodule update | ||
touch init-submodules | ||
git submodule update --init $(CPP_NETLIB_DIR) && \ |
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.
Same here, you can just put both of them on the same line:
git submodule update --init $(CPP_NETLIB_DIR) $(YAML_CPP_DIR)
test/Makefile
Outdated
purge: clean | ||
git submodule deinit -f --all | ||
|
||
init-submodules: |
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.
Unless you want to re-init the submodules all the time, you shouldn't make init-submodules
a phony target.
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.
Done
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.
You need to also touch
it, like this.
test/Makefile
Outdated
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \ | ||
$(GTEST_SOURCEDIR)/gtest_main.cc | ||
|
||
$(GTEST_LIBS): build-googletest |
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.
Why have a phony target in the middle? This will re-archive every time. Just make $(GTEST_LIBS)
depend on $(GTEST_DIR)/Makefile
, gtest_main.a
and the object files. Or make the target an actual file.
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.
I made the target an actual file - now the only phony targets are clean, purge and all
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.
If that file is never created (and cleaned up), it might as well be a phony target... I was proposing this:
$(GTEST_LIBS): $(GTEST_DIR)/Makefile
$(AR) $(ARFLAGS) gtest_main.a gtest-all.o gtest_main.o
test/format_unittest.cc
Outdated
|
||
TEST(SubstituteTest, ValidFormat) { | ||
const std::string endpoint_format = | ||
"https://stackdriver.googleapis.com/v1beta2/projects/{{project_id}}"; |
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.
I wonder if we need to keep the original format string here. How about something like:
const std::string format_str("prefix|{{subst}}|postfix");
EXPECT_EQ("prefix|value|postfix",
format::Substitute(format_str, {{"subst", "value"}}));
? Ditto for other tests.
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.
Doesn't have to be. But it makes the test more descriptive of the use cases.
Updated.
test/format_unittest.cc
Outdated
|
||
namespace { | ||
|
||
TEST(SubstituteTest, ValidFormat) { |
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.
How about SingleSubstitution
?
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.
Sounds better. Done.
test/format_unittest.cc
Outdated
); | ||
} | ||
|
||
TEST(SubstituteTest, ValidFormatMultipleSubstitution) { |
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.
How about just MultipleSubstitutions
?
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.
Done
70449da
to
5aa2078
Compare
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.
Not done with this round, but some early comments.
test/Makefile
Outdated
# Where to find user code. | ||
SRC_DIR=../src | ||
SRCS=\ | ||
$(SRC_DIR)/format.cc |
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.
No, I meant something like:
../src/%.o: ../src/%.cc
cd ../src && $(MAKE) $(subst $@,../src/,)
Alternatively, you could just have:
$(OBJS): ../src/metadatad
../src/metadatad:
cd ../src && $(MAKE) all
test/Makefile
Outdated
purge: clean | ||
git submodule deinit -f --all | ||
|
||
init-submodules: |
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.
You need to also touch
it, like this.
test/Makefile
Outdated
|
||
$(OBJS): build-source | ||
$(TEST_OBJS): build-test | ||
unittest: $(GTEST_LIBS) $(OBJS) $(TEST_OBJS) |
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.
What I'm saying is: should we name this format-test
instead of unittest
? Because we'll have tests for other modules.
test/Makefile
Outdated
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \ | ||
$(GTEST_SOURCEDIR)/gtest_main.cc | ||
|
||
$(GTEST_LIBS): build-googletest |
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.
If that file is never created (and cleaned up), it might as well be a phony target... I was proposing this:
$(GTEST_LIBS): $(GTEST_DIR)/Makefile
$(AR) $(ARFLAGS) gtest_main.a gtest-all.o gtest_main.o
test/Makefile
Outdated
$(GTEST_DIR)/include/gtest/internal/*.h | ||
GTEST_SRCS_=$(GTEST_SOURCEDIR)/*.cc $(GTEST_SOURCEDIR)/*.h $(GTEST_HEADERS) | ||
|
||
CPP_NETLIB_DIR=$(LIBDIR)/cpp-netlib |
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.
Ok, let's add a TODO, please?
test/format_unittest.cc
Outdated
} | ||
|
||
TEST(SubstituteTest, MultipleSubstitutions) { | ||
const std::string format_str("prefix|{{subst}}|{{another_subst}}|postfix"); |
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.
[Optional] "prefix|{{first}}|middle|{{second}}|suffix"
.
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.
Done
test/format_unittest.cc
Outdated
namespace { | ||
|
||
TEST(SubstituteTest, SingleSubstitution) { | ||
const std::string format_str("prefix|{{subst}}|postfix"); |
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.
[Optional] I know I suggested postfix
in the first place, but suffix
might read slightly better... Up to you.
test/format_unittest.cc
Outdated
EXPECT_EQ( | ||
"prefix|value|value2|postfix", | ||
format::Substitute( | ||
format_str, {{"subst", "value"}, {"another_subst", "value2"}}) |
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.
[Optional] {{"first", "one"}, {"second", "two"}}
.
test/format_unittest.cc
Outdated
TEST(SubstituteTest, UnknownParameter) { | ||
const std::string format_str("prefix|{{subst}}|postfix"); | ||
EXPECT_THROW( | ||
format::Substitute(format_str, {{"another_subst", "value"}}), |
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.
[Optional] {{"unknown", "value"}}
.
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.
LGTM
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.
A couple of stragglers.
test/Makefile
Outdated
|
||
TEST_DIR=. | ||
TEST_SOURCES=$(wildcard $(TEST_DIR)/*_unittest.cc) | ||
TEST_OBJS=$(TEST_SOURCES:%.cc=%.o) |
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.
I think this needs to be:
TEST_OBJS=$(TEST_SOURCES:$(TEST_DIR)/%.cc=%.o)
Otherwise all TEST_OBJS
are going to be in $(TEST_DIR)
...
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.
Discussed offline. TEST_DIR is '.', so this works fine.
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.
[Optional] I realized later that $(TEST_DIR)
is .
, so this is optional, but may be worth doing in case we end up putting tests in a subdirectory, lest we forget to override this (since the test executables do depend on the .o
files being in the current directory).
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.
Given that we already have the $(TEST_DIR) variable, makes sense to use it explicitly. Done.
test/Makefile
Outdated
|
||
gtest-all.o: $(GTEST_SOURCEDIR)/gtest-all.cc | ||
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c -o $@ \ | ||
$(GTEST_SOURCEDIR)/gtest-all.cc |
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.
This can now be $^
, right? And will fit on the previous line.
Ditto for gtest_main.cc
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.
Done
test/Makefile
Outdated
|
||
|
||
$(SRC_DIR)/%.o: $(SRC_DIR)/%.cc | ||
cd $(SRC_DIR) && $(MAKE) $(subst $@,$(SRC_DIR)/,) |
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.
I may have gotten this wrong. The following works: $(MAKE) $(@:$(SRC_DIR)/%=%)
.
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.
LGTM
But see some optional comments.
test/Makefile
Outdated
|
||
TEST_DIR=. | ||
TEST_SOURCES=$(wildcard $(TEST_DIR)/*_unittest.cc) | ||
TEST_OBJS=$(TEST_SOURCES:%.cc=%.o) |
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.
[Optional] I realized later that $(TEST_DIR)
is .
, so this is optional, but may be worth doing in case we end up putting tests in a subdirectory, lest we forget to override this (since the test executables do depend on the .o
files being in the current directory).
test/Makefile
Outdated
$(GTEST_SOURCEDIR)/gtest-all.cc $(GTEST_SOURCEDIR)/gtest_main.cc: init-submodules | ||
|
||
gtest-all.o: $(GTEST_SOURCEDIR)/gtest-all.cc | ||
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c -o $@ $^ |
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.
[Optional] We could make it
$(CXX) -c $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -o $@ $^
to conform to the implicit rule. WDYT? Also below.
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.
Done - moved CXXFLAGS up as well.
test/Makefile
Outdated
$(AR) $(ARFLAGS) $@ $^ | ||
|
||
format_unittest: $(GTEST_LIB) format_unittest.o $(SRC_DIR)/format.o | ||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $^ -lpthread -o $@ |
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.
[Optional] We could make it:
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
and set LDLIBS
to -lpthread
(again, to ~ conform to the implicit rule).
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.
what about LDFLAGS? set that to CPPFLAGS?
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.
Minor.
test/Makefile
Outdated
$(GTEST_SOURCEDIR)/gtest-all.cc $(GTEST_SOURCEDIR)/gtest_main.cc: init-submodules | ||
|
||
gtest-all.o: $(GTEST_SOURCEDIR)/gtest-all.cc | ||
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -I$(GTEST_DIR) -o $@ $^ |
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.
This -I$(GTEST_DIR)
is part of $(CPPFLAGS)
, so let's put it right after (before $(CXXFLAGS)
).
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.
Done
test/Makefile
Outdated
|
||
CPPFLAGS+=-isystem $(GTEST_DIR)/include | ||
CXXFLAGS=-std=c++11 -g -pthread | ||
LDFLAGS=$(CPPFLAGS) |
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.
No need for this -- the linker ignores the -isystem
arguments. Just let $(LDFLAGS)
pick up the default (i.e., don't set it).
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.
Done
test/Makefile
Outdated
CPPFLAGS+=-isystem $(GTEST_DIR)/include | ||
CXXFLAGS=-std=c++11 -g -pthread | ||
LDFLAGS=$(CPPFLAGS) | ||
LDLIBS=-lpthread |
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.
[Optional] This may actually be implied by -pthread
, but it's harmless to keep as-is.
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.
This is required.
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.
This may not have been required had we set LDFLAGS=$(CXXFLAGS)
, but it's not a big deal either way.
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.
LGTM
This PR sets up the googletest framework, and adds a unit test for format.cc