mirror of
https://github.com/troglobit/libite.git
synced 2026-11-28 20:48:27 +00:00
rsync.c: Refactor unit tests to work on Travis as well.
Travis does not have `/bin/tree` installed, and since we do not output intermediate results from `make test`, there is no need to call `/bin/tree` unless `-v` is supplied to the test. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
3e337c7078
commit
bb67fb749d
1 file changed
+37
-23
@@ -198,7 +198,8 @@ static int prune(char *dst, char **new_files, int new_num)
|
|||||||
#define SRC BASE "src/"
|
#define SRC BASE "src/"
|
||||||
#define DST BASE "dst/"
|
#define DST BASE "dst/"
|
||||||
|
|
||||||
char *files[] = {
|
static int verbose = 0;
|
||||||
|
static char *files[] = {
|
||||||
SRC "sub1/1.tst",
|
SRC "sub1/1.tst",
|
||||||
SRC "sub1/2.tst",
|
SRC "sub1/2.tst",
|
||||||
SRC "sub1/3.tst",
|
SRC "sub1/3.tst",
|
||||||
@@ -240,51 +241,64 @@ void setup_test(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int run_test()
|
static void tree(char *heading, char *dir)
|
||||||
{
|
{
|
||||||
|
if (verbose) {
|
||||||
|
char cmd[128];
|
||||||
|
|
||||||
|
if (heading)
|
||||||
|
puts(heading);
|
||||||
|
|
||||||
|
snprintf(cmd, sizeof(cmd), "tree -np %s", dir);
|
||||||
|
if (system(cmd))
|
||||||
|
perror("Failed calling tree, not installed perhaps");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int run_test(void)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
setup_test();
|
setup_test();
|
||||||
puts("Before:");
|
tree("Before:", BASE);
|
||||||
system("tree -np " BASE);
|
|
||||||
|
|
||||||
rsync(SRC, DST, 0, NULL);
|
result += rsync(SRC, DST, 0, NULL);
|
||||||
puts("After:");
|
tree("After:", BASE);
|
||||||
system("tree -np " BASE);
|
|
||||||
cleanup_test();
|
cleanup_test();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
setup_test();
|
setup_test();
|
||||||
rsync(BASE "src", DST, 0, NULL);
|
result += rsync(BASE "src", DST, 0, NULL);
|
||||||
puts("Only partial rsync of src <-- No slash!");
|
tree("Only partial rsync of src <-- No slash!", BASE);
|
||||||
system("tree -np " BASE);
|
|
||||||
#if 0
|
#if 0
|
||||||
cleanup_test();
|
cleanup_test();
|
||||||
setup_test();
|
setup_test();
|
||||||
rsync(BASE "src/sub1", BASE "dst", 0, NULL);
|
result += rsync(BASE "src/sub1", BASE "dst", 0, NULL);
|
||||||
puts("Only partial rsync of src/sub1 <-- No slashes!!");
|
tree("Only partial rsync of src/sub1 <-- No slashes!!", BASE);
|
||||||
system("tree -np " BASE);
|
|
||||||
|
|
||||||
cleanup_test();
|
cleanup_test();
|
||||||
setup_test();
|
setup_test();
|
||||||
rsync(BASE "src/sub1/", DST, 0, NULL);
|
result += rsync(BASE "src/sub1/", DST, 0, NULL);
|
||||||
puts("Only partial rsync of src/sub1/");
|
tree("Only partial rsync of src/sub1/", BASE);
|
||||||
system("tree -np " BASE);
|
|
||||||
|
|
||||||
cleanup_test();
|
cleanup_test();
|
||||||
setup_test();
|
setup_test();
|
||||||
rsync(BASE "src/sub1", DST, 0, NULL);
|
result += rsync(BASE "src/sub1", DST, 0, NULL);
|
||||||
puts("Only partial rsync of src/sub1 <-- No slash!");
|
tree("Only partial rsync of src/sub1 <-- No slash!", BASE);
|
||||||
system("tree -np " BASE);
|
|
||||||
|
|
||||||
rsync("/etc", "/var/tmp", 0, NULL);
|
result += rsync("/etc", "/var/tmp", 0, NULL);
|
||||||
puts("Real life test:");
|
tree("Real life test:", "/var/tmp");
|
||||||
system("tree -np /var/tmp");
|
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
if (argc > 1)
|
||||||
|
verbose = !strncmp("-v", argv[1], 2);
|
||||||
|
|
||||||
atexit(cleanup_test);
|
atexit(cleanup_test);
|
||||||
|
|
||||||
return run_test();
|
return run_test();
|
||||||
|
|||||||
Reference in new issue
Block a user