From a7e016c2c633667b561a0f26ebde88cb26571d1c Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Fri, 10 May 2024 21:15:30 +0200 Subject: Build static and dynamic libs --- test-ymake.cpp | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 171 insertions(+), 1 deletion(-) (limited to 'test-ymake.cpp') 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"( + + + hello + hello.cpp + + +)"); + + fs::create_directory("subdir1"); + + create_file("subdir1/second.cpp", R"(int main(int argc, char* argv[]) +{ + return 0; +})"); + + create_file("subdir1/YMakefile", R"( + + + second + second.cpp + + +)"); + + std::vector 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"( + + + hello.a + hello.cpp + second.cpp + + +)"); + + std::vector 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"( + + + hello.so.1.2.3 + hello.cpp + second.cpp + + +)"); + + std::vector 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) { -- cgit v1.2.3