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',
'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.')
#include "ninja.h"
+#ifdef _WIN32
+#include <io.h>
+#endif
+
#include <gtest/gtest.h>
#include "build.h"
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;
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;
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]);
}
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]);
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]);
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_);
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_;
ASSERT_TRUE(ls->Finish());
ASSERT_NE("", ls->GetOutput());
- ASSERT_EQ(1, subprocs.finished_.size());
+ ASSERT_EQ(1u, subprocs.finished_.size());
}
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());
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());