From a36049d505a7079b7c42fdc3fa733aaea0ec7a5c Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Fri, 31 May 2024 17:18:15 +0200 Subject: Use static lib in subdir, test --- test-ymake.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/test-ymake.cpp b/test-ymake.cpp index cf51a26..b5c030d 100644 --- a/test-ymake.cpp +++ b/test-ymake.cpp @@ -805,6 +805,72 @@ int main(int argc, char* argv[]) EXPECT_TRUE(!fs::exists("runmain")); } +TEST_F(ymakeTest, use_one_static_lib_from_subdir) +{ + create_file("YMakefile", R"( + + + runmain + runmain.cpp + subdir1/hello.a + + +)"); + + create_file("runmain.cpp", R"(#include "subdir1/hello.h" +int main(int argc, char* argv[]) +{ + hello(); + return 0; +})"); + + fs::create_directory("subdir1"); + create_file("subdir1/YMakefile", R"( + + + hello.a + hello.cpp + + +)"); + + create_file("subdir1/hello.cpp", R"(#include "hello.h" +#include +int hello() +{ + std::cout << "Hello." << std::endl; + return 0; +})"); + + create_file("subdir1/hello.h", R"(#pragma once +extern int hello(); +)"); + + std::vector output; + int result = run_command("../ymake", output); + EXPECT_EQ(result, 0); + ASSERT_EQ(output.size(), 4); // compile, link, compile, link + + EXPECT_TRUE(fs::exists("subdir1/hello.o")); + EXPECT_TRUE(fs::exists("subdir1/hello.a")); + EXPECT_TRUE(fs::exists("runmain.o")); + EXPECT_TRUE(fs::exists("runmain")); + + result = run_command("./runmain", output); + EXPECT_EQ(result, 0); + ASSERT_EQ(output.size(), 1); + EXPECT_EQ(output[0], "Hello."); + + result = run_command("../ymake clean", output); + EXPECT_EQ(result, 0); + ASSERT_EQ(output.size(), 6); // hello.o, hello.d, hello.a, runmain.o, runmain.d, runmain + + EXPECT_TRUE(!fs::exists("subdir1/hello.o")); + EXPECT_TRUE(!fs::exists("subdir1/hello.a")); + EXPECT_TRUE(!fs::exists("runmain.o")); + EXPECT_TRUE(!fs::exists("runmain")); +} + TEST_F(ymakeTest, use_one_dynamic_lib) { create_file("YMakefile", R"( @@ -870,7 +936,6 @@ int main(int argc, char* argv[]) } // TODO: -// use static lib from subdir // use dynamic lib from subdir // use static lib from subdir in subdir // use dynamic lib from subdir in subdir -- cgit v1.2.3