diff options
| -rw-r--r-- | Builder.cpp | 7 | ||||
| -rw-r--r-- | Builder.h | 1 | ||||
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | test-ymake.cpp | 109 | ||||
| -rw-r--r-- | yscan.cpp | 3 | 
5 files changed, 106 insertions, 16 deletions
| diff --git a/Builder.cpp b/Builder.cpp index c59aec8..51ac90f 100644 --- a/Builder.cpp +++ b/Builder.cpp @@ -180,10 +180,12 @@ namespace {  }  Builder::Builder(const pt::ptree& ptree): + _ptree(ptree),   _all_targets{get_all_targets(ptree)}, - _all_objects{get_all_objects(ptree)}, - _dependencies{get_dependencies(ptree)} + _all_objects{get_all_objects(ptree)}  { + // intentionally defer creation of _dependencies to build() + // to prevent creation of .d files in clean()  }  std::vector<fs::path> Builder::dependencies_of(const fs::path& p) const @@ -311,6 +313,7 @@ void Builder::build_filelist() {  // build everything according to specified configuration  void Builder::build() { + _dependencies = get_dependencies(_ptree);   // create build list by depth-first search   //std::cout << "Calculating build list..." << std::endl; @@ -26,6 +26,7 @@ private:   void cleanup(); + const boost::property_tree::ptree _ptree;   std::vector<std::filesystem::path> _all_targets;   std::vector<std::filesystem::path> _all_objects;   std::unordered_map<std::filesystem::path, std::vector<std::filesystem::path>> _dependencies; @@ -48,7 +48,7 @@ install:  	cp $(YSCAN) $(DESTDIR)/usr/bin/  clean: -	-rm -f *.o $(PROJECTNAME) $(YSCAN) +	-rm -f *.o $(PROJECTNAME) $(YSCAN) $(TEST)  	-dh_clean  deb: diff --git a/test-ymake.cpp b/test-ymake.cpp index a4d9aa4..fcd424f 100644 --- a/test-ymake.cpp +++ b/test-ymake.cpp @@ -15,16 +15,16 @@ namespace {   const fs::path testpath{"testdir1"};  } -class BuildTest: public ::testing::Test +class ymakeTest: public ::testing::Test  {  private:   fs::path original_path;  protected: - BuildTest() { + ymakeTest() {   } - ~BuildTest() override { + ~ymakeTest() override {   }   void SetUp() override { @@ -45,6 +45,10 @@ protected:  }; +class yscanTest: public ymakeTest +{ +}; +  void create_file(const fs::path& path, const std::string& contents)  {   Reichwein::File::setFile(path, contents); @@ -55,19 +59,27 @@ int run_command(const std::string& command)   return bp::system(command, bp::std_out > bp::null, bp::std_err > bp::null);  } -int run_command(const std::string& command, std::vector<std::string>& output) +int run_command(const std::string& command, std::string& output)  {   bp::ipstream is;   bp::ipstream es;   int result = bp::system(command, bp::std_out > is, bp::std_err > es); - std::string output_string(std::istreambuf_iterator<char>(is), {}); - output_string += std::string(std::istreambuf_iterator<char>(es), {}); - output = Reichwein::Stringhelper::split(output_string, "\r\n"); + output = std::string(std::istreambuf_iterator<char>(is), {}); + output += std::string(std::istreambuf_iterator<char>(es), {}); + + return result; +} +int run_command(const std::string& command, std::vector<std::string>& output) +{ + std::string output_string; + int result = run_command(command, output_string); + + output = Reichwein::Stringhelper::split(output_string, "\r\n");   return result;  } -TEST_F(BuildTest, build_one_cpp) +TEST_F(ymakeTest, build_one_cpp)  {   create_file("hello.cpp", R"(int main(int argc, char* argv[])  { @@ -90,7 +102,7 @@ TEST_F(BuildTest, build_one_cpp)   EXPECT_EQ(output.size(), 2); // compile, link  } -TEST_F(BuildTest, build_one_cpp_compile_error) +TEST_F(ymakeTest, build_one_cpp_compile_error)  {   create_file("hello.cpp", R"(int main(int argc, char* argv[])  { @@ -110,7 +122,7 @@ TEST_F(BuildTest, build_one_cpp_compile_error)   EXPECT_NE(result, 0);  } -TEST_F(BuildTest, clean_one_cpp) +TEST_F(ymakeTest, clean_one_cpp)  {   create_file("hello.cpp", R"(int main(int argc, char* argv[])  { @@ -140,7 +152,7 @@ TEST_F(BuildTest, clean_one_cpp)   ASSERT_EQ(result, 0);  } -TEST_F(BuildTest, YMakefile_missing) +TEST_F(ymakeTest, YMakefile_missing)  {   int result = run_command("../ymake");   EXPECT_NE(result, 0); @@ -149,3 +161,78 @@ TEST_F(BuildTest, YMakefile_missing)   EXPECT_NE(result, 0);  } +TEST_F(ymakeTest, build_three_cpp) +{ + create_file("hello.cpp", R"(int main(int argc, char* argv[]) +{ + return 0; +})"); + create_file("second.cpp", R"( +#include "second.h" +)"); + create_file("second.h", R"( +#pragma once +)"); + create_file("third.cpp", R"( +)"); + + create_file("YMakefile", R"( +<ymake> + <build> +  <name>hello</name> +  <source>hello.cpp</source> +  <source>second.cpp</source> +  <source>third.cpp</source> + </build> +</ymake> +)"); + + std::vector<std::string> output; + int result = run_command("../ymake", output); + EXPECT_EQ(result, 0); + + EXPECT_EQ(output.size(), 4); // compile 3, link 1 +} + +// TODO: test .c .cc .cpp +// TODO: multiple builds +// TODO: test tests + +TEST_F(yscanTest, no_cpp_file) +{ + std::string output; + int result = run_command("../yscan", output); + EXPECT_EQ(result, 0); + + EXPECT_EQ(output, R"(<ymake> + <build> +  <name>testdir1</name> + </build> +</ymake> +)"); +} + +TEST_F(yscanTest, one_cpp_file) +{ + create_file("hello.cpp", R"(int main(int argc, char* argv[]) +{ + return 0; +})"); + + std::string output; + int result = run_command("../yscan", output); + EXPECT_EQ(result, 0); + + EXPECT_EQ(output, R"(<ymake> + <build> +  <name>testdir1</name> +  <source>hello.cpp</source> + </build> +</ymake> +)"); +} + +// TODO: test multiple files +// TODO: test multiple builds +// TODO: test tests + @@ -42,8 +42,7 @@ int yscan(int argc, char* argv[])   <build>    <name>{}</name>  {} </build> -{}</ymake> -)"}; +{}</ymake>)"};    contents = fmt::format(contents, name, sources, test_sources);    std::cout << contents << std::endl;   } catch (const std::exception& ex) { | 
