Skip to content

Commit

Permalink
Tests now build on a native Windows build (tested with VS2010)
Browse files Browse the repository at this point in the history
All tests except SubProcess pass on a native Windows build
Tests continue not to build on a platform=mingw build
  • Loading branch information
philipcraig committed May 28, 2011
1 parent 511613c commit 41a4e26
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/build_log.cc 100644 → 100755
Expand Up @@ -54,7 +54,7 @@ bool BuildLog::OpenForWrite(const string& path, string* err) {
*err = strerror(errno);
return false;
}
setvbuf(log_file_, NULL, _IOLBF, 0);
setvbuf(log_file_, NULL, _IOLBF, BUFSIZ);

if (ftell(log_file_) == 0) {
if (fwrite(kFileSignature, sizeof(kFileSignature) - 1, 1, log_file_) < 1) {
Expand Down
11 changes: 11 additions & 0 deletions src/build_log_test.cc 100644 → 100755
Expand Up @@ -16,6 +16,10 @@

#include "test.h"

#ifdef WIN32
#include <fcntl.h>
#endif

static const char kTestFilename[] = "BuildLogTest-tempfile";

struct BuildLogTest : public StateTestWithBuiltinRules {
Expand Down Expand Up @@ -90,7 +94,14 @@ TEST_F(BuildLogTest, Truncate) {
// For all possible truncations of the input file, assert that we don't
// crash or report an error when parsing.
for (off_t size = statbuf.st_size; size > 0; --size) {
#ifndef WIN32
ASSERT_EQ(0, truncate(kTestFilename, size));
#else
int fh;
ASSERT_EQ(0, _sopen_s(&fh, kTestFilename, _O_RDWR | _O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE));
ASSERT_EQ(0, _chsize(fh, size));
_close(fh);
#endif

BuildLog log2;
EXPECT_TRUE(log2.Load(kTestFilename, &err));
Expand Down
2 changes: 1 addition & 1 deletion src/ninja_test.cc 100644 → 100755
Expand Up @@ -217,7 +217,7 @@ TEST_F(StatTest, Middle) {
#ifndef _mktemp_s
/// mingw has no mktemp. Implement one with the same type as the one
/// found in the Windows API.
int _mktemp_s(const char* templ) {
int _mktemp_s(char* templ) {
char* ofs = strchr(templ, 'X');
sprintf(ofs, "%d", rand() % 1000000);
return 0;
Expand Down
3 changes: 3 additions & 0 deletions src/util.cc 100644 → 100755
Expand Up @@ -25,7 +25,10 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>

#ifndef _WIN32
#include <sys/time.h>
#endif

#include <vector>

Expand Down
4 changes: 4 additions & 0 deletions src/util.h 100644 → 100755
Expand Up @@ -46,4 +46,8 @@ int ReadFile(const string& path, string* contents, string* err);
/// time.
int64_t GetTimeMillis();

#ifdef _WIN32
#define snprintf _snprintf
#endif

#endif // NINJA_UTIL_H_

0 comments on commit 41a4e26

Please sign in to comment.