diff options
Diffstat (limited to 'cat/test')
-rw-r--r-- | cat/test/main.c | 30 | ||||
-rw-r--r-- | cat/test/test.h | 1 |
2 files changed, 30 insertions, 1 deletions
diff --git a/cat/test/main.c b/cat/test/main.c index 0aa1deb5..24071baf 100644 --- a/cat/test/main.c +++ b/cat/test/main.c @@ -1360,6 +1360,31 @@ assertion_file_birthtime_recent(const char *file, int line, return assertion_file_time(file, line, pathname, 0, 0, 'b', 1); } +/* Verify mode of 'pathname'. */ +int +assertion_file_mode(const char *file, int line, const char *pathname, int expected_mode) +{ + int mode; + int r; + + assertion_count(file, line); +#if defined(_WIN32) && !defined(__CYGWIN__) + failure_start(file, line, "assertFileMode not yet implemented for Windows"); +#else + { + struct stat st; + r = lstat(pathname, &st); + mode = (int)(st.st_mode & 0777); + } + if (r == 0 && mode == expected_mode) + return (1); + failure_start(file, line, "File %s has mode %o, expected %o", + pathname, mode, expected_mode); +#endif + failure_finish(NULL); + return (0); +} + /* Verify mtime of 'pathname'. */ int assertion_file_mtime(const char *file, int line, @@ -1578,8 +1603,10 @@ assertion_make_dir(const char *file, int line, const char *dirname, int mode) if (0 == _mkdir(dirname)) return (1); #else - if (0 == mkdir(dirname, mode)) + if (0 == mkdir(dirname, mode)) { + assertion_file_mode(file, line, dirname, mode); return (1); + } #endif failure_start(file, line, "Could not create directory %s", dirname); failure_finish(NULL); @@ -1644,6 +1671,7 @@ assertion_make_file(const char *file, int line, } } close(fd); + assertion_file_mode(file, line, path, mode); return (1); #endif } diff --git a/cat/test/test.h b/cat/test/test.h index 704a137e..35a0bc79 100644 --- a/cat/test/test.h +++ b/cat/test/test.h @@ -241,6 +241,7 @@ int assertion_file_birthtime_recent(const char *, int, const char *); int assertion_file_contains_lines_any_order(const char *, int, const char *, const char **); int assertion_file_contents(const char *, int, const void *, int, const char *); int assertion_file_exists(const char *, int, const char *); +int assertion_file_mode(const char *, int, const char *, int); int assertion_file_mtime(const char *, int, const char *, long, long); int assertion_file_mtime_recent(const char *, int, const char *); int assertion_file_nlinks(const char *, int, const char *, int); |