summaryrefslogtreecommitdiffhomepage
path: root/test-ymake.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test-ymake.cpp')
-rw-r--r--test-ymake.cpp109
1 files changed, 98 insertions, 11 deletions
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
+