summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgen-build-file.py17
-rw-r--r--src/build_log_test.cc4
-rw-r--r--src/graph_test.cc2
-rw-r--r--src/ninja_test.cc70
-rw-r--r--src/subprocess_test.cc10
5 files changed, 70 insertions, 33 deletions
diff --git a/gen-build-file.py b/gen-build-file.py
index d1f740a..48c0f6a 100755
--- a/gen-build-file.py
+++ b/gen-build-file.py
@@ -51,18 +51,23 @@ n.variable('builddir', 'build')
cflags = ['-O2', '-g', '-Wall', '-Wno-deprecated', '-fno-exceptions',
'-fvisibility=hidden', '-pipe']
+ldflags = []
if platform == 'mingw':
n.variable('cxx', 'i586-mingw32msvc-c++')
# "warning: visibility attribute not supported in this
# configuration; ignored"
cflags.remove('-fvisibility=hidden')
+ cflags.append('-Igtest-1.6.0/include')
+ ldflags.append('-Lgtest-1.6.0/lib/.libs')
else:
n.variable('cxx', os.environ.get('CXX', 'g++'))
+
if 'CFLAGS' in os.environ:
cflags.append(os.environ['CFLAGS'])
n.variable('cflags', ' '.join(cflags))
-
-n.variable('ldflags', os.environ.get('LDFLAGS', ''))
+if 'LDFLAGS' in os.environ:
+ ldflags.append(os.environ['LDFLAGS'])
+n.variable('ldflags', ' '.join(ldflags))
n.newline()
n.rule('cxx',
@@ -124,12 +129,12 @@ for name in ['build_test', 'build_log_test', 'graph_test', 'ninja_test',
'parsers_test', 'subprocess_test', 'util_test', 'clean_test',
'test']:
objs += cxx(name)
-ldflags = '-lgtest -lgtest_main -lpthread'
-if 'LDFLAGS' in os.environ:
- ldflags += ' ' + os.environ.get('LDFLAGS')
+ldflags.append('-lgtest_main -lgtest')
+if platform != 'mingw':
+ ldflags.append('-lpthread')
n.build('ninja_test', 'link', objs, implicit=ninja_lib, order_only=ninja_lib,
variables=[('libs', '-L$builddir -lninja'),
- ('ldflags', ldflags)])
+ ('ldflags', ' '.join(ldflags))])
n.newline()
n.comment('Generate a graph using the "graph" tool.')
diff --git a/src/build_log_test.cc b/src/build_log_test.cc
index 26021d5..66f88c3 100644
--- a/src/build_log_test.cc
+++ b/src/build_log_test.cc
@@ -43,8 +43,8 @@ TEST_F(BuildLogTest, WriteRead) {
EXPECT_TRUE(log2.Load(kTestFilename, &err));
ASSERT_EQ("", err);
- ASSERT_EQ(2, log1.log_.size());
- ASSERT_EQ(2, log2.log_.size());
+ ASSERT_EQ(2u, log1.log_.size());
+ ASSERT_EQ(2u, log2.log_.size());
BuildLog::LogEntry* e1 = log1.LookupByOutput("out");
ASSERT_TRUE(e1);
BuildLog::LogEntry* e2 = log2.LookupByOutput("out");
diff --git a/src/graph_test.cc b/src/graph_test.cc
index 7b28e87..9a5035c 100644
--- a/src/graph_test.cc
+++ b/src/graph_test.cc
@@ -107,7 +107,7 @@ TEST_F(GraphTest, RootNodes) {
string err;
vector<Node*> root_nodes = state_.RootNodes(&err);
- EXPECT_EQ(4, root_nodes.size());
+ EXPECT_EQ(4u, root_nodes.size());
for (size_t i = 0; i < root_nodes.size(); ++i) {
string name = root_nodes[i]->file_->path_;
EXPECT_EQ("out", name.substr(0, 3));
diff --git a/src/ninja_test.cc b/src/ninja_test.cc
index ed22709..93873b3 100644
--- a/src/ninja_test.cc
+++ b/src/ninja_test.cc
@@ -14,6 +14,10 @@
#include "ninja.h"
+#ifdef _WIN32
+#include <io.h>
+#endif
+
#include <gtest/gtest.h>
#include "build.h"
@@ -81,7 +85,7 @@ TEST(EvalString, Error) {
size_t err_index;
EXPECT_FALSE(str.Parse("bad $", &err, &err_index));
EXPECT_EQ("expected variable after $", err);
- EXPECT_EQ(5, err_index);
+ EXPECT_EQ(5u, err_index);
}
TEST(EvalString, CurlyError) {
EvalString str;
@@ -89,7 +93,7 @@ TEST(EvalString, CurlyError) {
size_t err_index;
EXPECT_FALSE(str.Parse("bad ${bar", &err, &err_index));
EXPECT_EQ("expected closing curly after ${", err);
- EXPECT_EQ(9, err_index);
+ EXPECT_EQ(9u, err_index);
}
TEST(EvalString, Curlies) {
EvalString str;
@@ -137,10 +141,10 @@ TEST_F(StatTest, Simple) {
Node* out = GetNode("out");
out->file_->Stat(this);
- ASSERT_EQ(1, stats_.size());
+ ASSERT_EQ(1u, stats_.size());
Edge* edge = out->in_edge_;
edge->RecomputeDirty(NULL, this, NULL);
- ASSERT_EQ(2, stats_.size());
+ ASSERT_EQ(2u, stats_.size());
ASSERT_EQ("out", stats_[0]);
ASSERT_EQ("in", stats_[1]);
}
@@ -152,10 +156,10 @@ TEST_F(StatTest, TwoStep) {
Node* out = GetNode("out");
out->file_->Stat(this);
- ASSERT_EQ(1, stats_.size());
+ ASSERT_EQ(1u, stats_.size());
Edge* edge = out->in_edge_;
edge->RecomputeDirty(NULL, this, NULL);
- ASSERT_EQ(3, stats_.size());
+ ASSERT_EQ(3u, stats_.size());
ASSERT_EQ("out", stats_[0]);
ASSERT_TRUE(GetNode("out")->dirty_);
ASSERT_EQ("mid", stats_[1]);
@@ -171,10 +175,10 @@ TEST_F(StatTest, Tree) {
Node* out = GetNode("out");
out->file_->Stat(this);
- ASSERT_EQ(1, stats_.size());
+ ASSERT_EQ(1u, stats_.size());
Edge* edge = out->in_edge_;
edge->RecomputeDirty(NULL, this, NULL);
- ASSERT_EQ(1 + 6, stats_.size());
+ ASSERT_EQ(1u + 6u, stats_.size());
ASSERT_EQ("mid1", stats_[1]);
ASSERT_TRUE(GetNode("mid1")->dirty_);
ASSERT_EQ("in11", stats_[2]);
@@ -191,7 +195,7 @@ TEST_F(StatTest, Middle) {
Node* out = GetNode("out");
out->file_->Stat(this);
- ASSERT_EQ(1, stats_.size());
+ ASSERT_EQ(1u, stats_.size());
Edge* edge = out->in_edge_;
edge->RecomputeDirty(NULL, this, NULL);
ASSERT_FALSE(GetNode("in")->dirty_);
@@ -199,29 +203,57 @@ TEST_F(StatTest, Middle) {
ASSERT_TRUE(GetNode("out")->dirty_);
}
+#ifdef _WIN32
+#ifndef _mktemp_s
+/* mingw has no mktemp. */
+int _mktemp_s(const char* templ) {
+ char* ofs = strchr(templ, 'X');
+ sprintf(ofs, "%d", rand() % 1000000);
+ return 0;
+}
+#endif
+#endif
+
class DiskInterfaceTest : public testing::Test {
public:
virtual void SetUp() {
char buf[4 << 10];
ASSERT_TRUE(getcwd(buf, sizeof(buf)));
start_dir_ = buf;
+ temp_dir_name_ = SetupTempDir();
+ printf("temp dir: %s\n", temp_dir_name_.c_str());
- const char* tempdir = getenv("TMPDIR");
- if (!tempdir)
- tempdir = "/tmp";
- ASSERT_EQ(0, chdir(tempdir));
-
- char name_template[] = "DiskInterfaceTest-XXXXXX";
- char* name = mkdtemp(name_template);
- temp_dir_name_ = name;
- ASSERT_TRUE(name);
- ASSERT_EQ(0, chdir(name));
+ ASSERT_FALSE(temp_dir_name_.empty());
+ ASSERT_EQ(0, chdir(temp_dir_name_.c_str()));
}
+
virtual void TearDown() {
ASSERT_EQ(0, chdir(start_dir_.c_str()));
ASSERT_EQ(0, system(("rm -rf " + temp_dir_name_).c_str()));
}
+ string SetupTempDir() {
+ char name_template[] = "DiskInterfaceTest-XXXXXX";
+ char* name = NULL;
+
+ const char* tempdir = getenv("TMPDIR");
+ if (!tempdir)
+ tempdir = "/tmp";
+
+#ifdef _WIN32
+ if (_chdir(tempdir) < 0)
+ return "";
+ if (_mktemp_s(name_template) < 0)
+ return "";
+ name = name_template;
+#else
+ if (chdir(tempdir) < 0)
+ return "";
+ name = mkdtemp(name_template);
+#endif
+ return name ? name : "";
+ }
+
string start_dir_;
string temp_dir_name_;
RealDiskInterface disk_;
diff --git a/src/subprocess_test.cc b/src/subprocess_test.cc
index a72f1cb..c158810 100644
--- a/src/subprocess_test.cc
+++ b/src/subprocess_test.cc
@@ -50,7 +50,7 @@ TEST(SubprocessSet, Single) {
ASSERT_TRUE(ls->Finish());
ASSERT_NE("", ls->GetOutput());
- ASSERT_EQ(1, subprocs.finished_.size());
+ ASSERT_EQ(1u, subprocs.finished_.size());
}
TEST(SubprocessSet, Multi) {
@@ -68,7 +68,7 @@ TEST(SubprocessSet, Multi) {
subprocs.Add(processes[i]);
}
- ASSERT_EQ(3, subprocs.running_.size());
+ ASSERT_EQ(3u, subprocs.running_.size());
for (int i = 0; i < 3; ++i) {
ASSERT_FALSE(processes[i]->Done());
ASSERT_EQ("", processes[i]->GetOutput());
@@ -76,12 +76,12 @@ TEST(SubprocessSet, Multi) {
while (!processes[0]->Done() || !processes[1]->Done() ||
!processes[2]->Done()) {
- ASSERT_GT(subprocs.running_.size(), 0);
+ ASSERT_GT(subprocs.running_.size(), 0u);
subprocs.DoWork();
}
- ASSERT_EQ(0, subprocs.running_.size());
- ASSERT_EQ(3, subprocs.finished_.size());
+ ASSERT_EQ(0u, subprocs.running_.size());
+ ASSERT_EQ(3u, subprocs.finished_.size());
for (int i = 0; i < 3; ++i) {
ASSERT_TRUE(processes[i]->Finish());