From ec955eb6726b31e26d17c34474619b60f3563194 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 15 Jun 2024 14:24:14 +0200 Subject: Automatically depend on YMakefile (rebuild if necessary), tests --- test-ymake.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 2 deletions(-) (limited to 'test-ymake.cpp') diff --git a/test-ymake.cpp b/test-ymake.cpp index 9d6cd43..973e827 100644 --- a/test-ymake.cpp +++ b/test-ymake.cpp @@ -171,11 +171,16 @@ TEST_F(ymakeTest, clean_one_cpp) TEST_F(ymakeTest, YMakefile_missing) { - int result = run_command("../ymake"); + std::vector output; + int result = run_command("../ymake", output); EXPECT_NE(result, 0); + ASSERT_EQ(output.size(), 1); + EXPECT_EQ(output[0], "ymake: YMakefile not found"); - result = run_command("../ymake clean"); + result = run_command("../ymake clean", output); EXPECT_NE(result, 0); + ASSERT_EQ(output.size(), 1); + EXPECT_EQ(output[0], "ymake: YMakefile not found"); } TEST_F(ymakeTest, build_three_cpp) @@ -229,6 +234,41 @@ TEST_F(ymakeTest, build_three_cpp) EXPECT_TRUE(!fs::exists("hello")); } +TEST_F(ymakeTest, rebuild) +{ + 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("YMakefile", R"( + + + hello + hello.cpp + second.cpp + + +)"); + + std::vector output; + int result = run_command("../ymake", output); + EXPECT_EQ(result, 0); + + EXPECT_EQ(output.size(), 3); // compile 2, link 1 + + run_command("touch hello.cpp"); + result = run_command("../ymake", output); + EXPECT_EQ(result, 0); + EXPECT_EQ(output.size(), 2); // compile 1, link 1 +} + TEST_F(ymakeTest, build_cpp_c_cc) { create_file("hello.cpp", R"(int main(int argc, char* argv[]) @@ -1181,6 +1221,47 @@ __attribute__((visibility("default"))) int hello(); EXPECT_TRUE(!fs::exists("runmain")); } +TEST_F(ymakeTest, dependencies_on_YMakefile) +{ + create_file("hello.cpp", R"(int main(int argc, char* argv[]) +{ + return 0; +})"); + + create_file("YMakefile", R"( + + + hello + hello.cpp + + +)"); + + std::vector output; + int result = run_command("../ymake", output); + EXPECT_EQ(result, 0); + + EXPECT_EQ(output.size(), 2); // compile, link + + result = run_command("./hello", output); + EXPECT_EQ(result, 0); + EXPECT_EQ(output.size(), 0); // run + + result = run_command("../ymake", output); + EXPECT_EQ(result, 0); + EXPECT_EQ(output.size(), 1); // "Everything up to date" + EXPECT_EQ(output[0], "Everything up to date."); + + result = run_command("touch YMakefile"); + EXPECT_EQ(result, 0); + + result = run_command("../ymake", output); + EXPECT_EQ(result, 0); + + EXPECT_EQ(output.size(), 2); // compile, link +} + + TEST_F(yscanTest, no_cpp_file) { std::string output; -- cgit v1.2.3