35 int _mktemp_s(
char* templ) {
36 char* ofs = strchr(templ,
'X');
37 sprintf(ofs,
"%d", rand() % 1000000);
43 char* mkdtemp(
char* name_template) {
44 int err = _mktemp_s(name_template);
50 err = _mkdir(name_template);
60 string GetSystemTempDir() {
63 if (!GetTempPath(
sizeof(buf), buf))
67 const char* tempdir = getenv(
"TMPDIR");
83 " command = cat $in > $out\n");
93 ASSERT_TRUE(parser.
ParseTest(input, &err)) << err;
102 const string& contents) {
104 files_[path].contents = contents;
109 FileMap::iterator i =
files_.find(path);
111 return i->second.mtime;
127 FileMap::iterator i =
files_.find(path);
129 return i->second.contents;
137 FileMap::iterator i =
files_.find(path);
151 Fatal(
"couldn't get system temp dir");
153 Fatal(
"chdir: %s", strerror(errno));
156 char name_template[1024];
157 strcpy(name_template, name.c_str());
158 strcat(name_template,
"-XXXXXX");
159 char* tempname = mkdtemp(name_template);
161 Fatal(
"mkdtemp: %s", strerror(errno));
166 Fatal(
"chdir: %s", strerror(errno));
175 Fatal(
"chdir: %s", strerror(errno));
182 if (system(command.c_str()) < 0)
183 Fatal(
"system: %s", strerror(errno));
virtual TimeStamp Stat(const string &path)
stat() a file, returning the mtime, or 0 if missing and -1 on other errors.
Node * GetNode(const string &path)
Short way to get a Node by its path from state_.
Node * GetNode(StringPiece path)
Information about a node in the dependency graph: the file, whether it's dirty, mtime, etc.
set< string > files_removed_
virtual bool WriteFile(const string &path, const string &contents)
Create a file, with the specified name and contents Returns true on success, false on failure...
int now_
A simple fake timestamp for file operations.
StateTestWithBuiltinRules()
void AssertParse(State *state, const char *input)
void Create(const string &path, const string &contents)
"Create" a file with contents.
set< string > files_created_
vector< string > directories_made_
void AddCatRule(State *state)
Add a "cat" rule to state.
string start_dir_
The temp directory containing our dir.
virtual bool MakeDir(const string &path)
Create a directory, returning false on failure.
void Fatal(const char *msg,...)
Log a fatal message and exit.
void Cleanup()
Clean up the temporary directory.
static uint64_t HashCommand(StringPiece command)
void CreateAndEnter(const string &name)
Create a temporary directory and chdir into it.
virtual string ReadFile(const string &path, string *err)
Read a file to a string. Fill in |err| on error.
Global state (file status, loaded rules) for a single run.
vector< string > files_read_
virtual int RemoveFile(const string &path)
Remove the file named path.
unsigned long long uint64_t
void AssertHash(const char *expected, uint64_t actual)
string temp_dir_name_
The subdirectory name for our dir, or empty if it hasn't been set up.
bool ParseTest(const string &input, string *err)
Parse a text string of input. Used by tests.