summaryrefslogtreecommitdiff
path: root/cat
diff options
context:
space:
mode:
authorGraham Percival <gperciva@tarsnap.com>2016-09-26 12:20:25 -0700
committerGraham Percival <gperciva@tarsnap.com>2016-09-26 12:44:56 -0700
commit0f14b0816b2422bd4478e68610a4b6c67f9f68e1 (patch)
tree5e671c4a89c23933b3ee95bfed2d6ca86c900097 /cat
parent75de4e4a21d3564f1255681695672840792cb52b (diff)
downloadlibarchive-0f14b0816b2422bd4478e68610a4b6c67f9f68e1.tar.gz
Add and use assertion_file_mode() in other tests
This adds the assertion_file_mode() function from libarchive/test/main.c and applies it to cat/test/main.c cpio/test/main.c tar/test/main.c Sponsored by: Tarsnap Backup Inc.
Diffstat (limited to 'cat')
-rw-r--r--cat/test/main.c30
-rw-r--r--cat/test/test.h1
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);