diff options
Diffstat (limited to 'test-ymake.cpp')
-rw-r--r-- | test-ymake.cpp | 172 |
1 files changed, 171 insertions, 1 deletions
diff --git a/test-ymake.cpp b/test-ymake.cpp index 3aea372..c2dd78e 100644 --- a/test-ymake.cpp +++ b/test-ymake.cpp @@ -491,7 +491,177 @@ TEST_F(ymakeTest, build_with_clang) } } -// TODO: multiple dirs / YMakefiles +TEST_F(ymakeTest, multiple_dirs) +{ + create_file("hello.cpp", R"(int main(int argc, char* argv[]) +{ + return 0; +})"); + + create_file("YMakefile", R"( +<ymake> + <build> + <name>hello</name> + <source>hello.cpp</source> + </build> +</ymake> +)"); + + fs::create_directory("subdir1"); + + create_file("subdir1/second.cpp", R"(int main(int argc, char* argv[]) +{ + return 0; +})"); + + create_file("subdir1/YMakefile", R"( +<ymake> + <build> + <name>second</name> + <source>second.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, link, compile, link + + EXPECT_TRUE(fs::exists("hello")); + EXPECT_TRUE(fs::exists("hello.o")); + EXPECT_TRUE(fs::exists("hello.d")); + + EXPECT_TRUE(fs::exists("subdir1/second")); + EXPECT_TRUE(fs::exists("subdir1/second.o")); + EXPECT_TRUE(fs::exists("subdir1/second.d")); + + result = run_command("../ymake", output); + EXPECT_EQ(result, 0); + EXPECT_EQ(output.size(), 1); // everything up to date + + result = run_command("../ymake clean", output); + EXPECT_EQ(result, 0); + EXPECT_EQ(output.size(), 6); // hello hello.o hello.d second second.o second.d + + result = run_command("../ymake clean", output); + EXPECT_EQ(result, 0); + EXPECT_EQ(output.size(), 0); +} + +TEST_F(ymakeTest, build_one_static_lib) +{ + create_file("hello.cpp", R"(int maine(int argc, char* argv[]) +{ + return 0; +})"); + create_file("second.cpp", R"(int maini(int argc, char* argv[]) +{ + return 0; +})"); + + create_file("YMakefile", R"( +<ymake> + <build> + <name>hello.a</name> + <source>hello.cpp</source> + <source>second.cpp</source> + </build> +</ymake> +)"); + + std::vector<std::string> output; + int result = run_command("../ymake", output); + EXPECT_EQ(result, 0); + + ASSERT_EQ(output.size(), 3); // 2x compile, link + EXPECT_EQ(output[2].substr(0, 7), "ar rcs "); + + EXPECT_TRUE(fs::exists("hello.d")); + EXPECT_TRUE(fs::exists("hello.o")); + EXPECT_TRUE(fs::exists("hello.a")); + + EXPECT_TRUE(fs::exists("second.d")); + EXPECT_TRUE(fs::exists("second.o")); + + result = run_command("../ymake", output); + EXPECT_EQ(result, 0); + ASSERT_EQ(output.size(), 1); // everything up to date + + result = run_command("../ymake clean", output); + EXPECT_EQ(result, 0); + ASSERT_EQ(output.size(), 5); // deleted 5 files + + EXPECT_TRUE(!fs::exists("hello.d")); + EXPECT_TRUE(!fs::exists("hello.o")); + EXPECT_TRUE(!fs::exists("hello.a")); + + EXPECT_TRUE(!fs::exists("second.d")); + EXPECT_TRUE(!fs::exists("second.o")); + + result = run_command("../ymake clean", output); + EXPECT_EQ(result, 0); + ASSERT_EQ(output.size(), 0); +} + +TEST_F(ymakeTest, build_one_dynamic_lib) +{ + create_file("hello.cpp", R"(int maine(int argc, char* argv[]) +{ + return 0; +})"); + create_file("second.cpp", R"(int maini(int argc, char* argv[]) +{ + return 0; +})"); + + create_file("YMakefile", R"( +<ymake> + <build> + <name>hello.so.1.2.3</name> + <source>hello.cpp</source> + <source>second.cpp</source> + </build> +</ymake> +)"); + + std::vector<std::string> output; + int result = run_command("../ymake", output); + EXPECT_EQ(result, 0); + + ASSERT_EQ(output.size(), 3); // 2x compile, link + EXPECT_EQ(output[2].substr(0, 4), "g++ "); + + EXPECT_TRUE(fs::exists("hello.d")); + EXPECT_TRUE(fs::exists("hello.o")); + EXPECT_TRUE(fs::exists("hello.so.1.2.3")); + + EXPECT_TRUE(fs::exists("second.d")); + EXPECT_TRUE(fs::exists("second.o")); + + result = run_command("../ymake", output); + EXPECT_EQ(result, 0); + ASSERT_EQ(output.size(), 1); // everything up to date + + result = run_command("../ymake clean", output); + EXPECT_EQ(result, 0); + ASSERT_EQ(output.size(), 5); // deleted 5 files + + EXPECT_TRUE(!fs::exists("hello.d")); + EXPECT_TRUE(!fs::exists("hello.o")); + EXPECT_TRUE(!fs::exists("hello.so.1.2.3")); + + EXPECT_TRUE(!fs::exists("second.d")); + EXPECT_TRUE(!fs::exists("second.o")); + + result = run_command("../ymake clean", output); + EXPECT_EQ(result, 0); + ASSERT_EQ(output.size(), 0); +} + +// TODO: +// use static lib +// use dynamic lib TEST_F(yscanTest, no_cpp_file) { |