1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#include <stic.h>
#include <unistd.h> /* chdir() unlink() */
#include <stdio.h> /* fclose() fflush() fopen() fprintf() */
#include <test-utils.h>
#include "../../src/cfg/config.h"
#include "../../src/utils/fs.h"
#include "../../src/utils/str.h"
#include "../../src/utils/utils.h"
#include "../../src/cmd_completion.h"
#include "../../src/status.h"
static void line_handler(const char line[], void *arg);
static int nlines;
TEST(check_null_separation, IF(have_cat))
{
char *saved_cwd;
FILE *const f = fopen(SANDBOX_PATH "/list", "w");
fprintf(f, "%s%c", SANDBOX_PATH "/a\nb", '\0');
fclose(f);
saved_cwd = save_cwd();
assert_success(chdir(SANDBOX_PATH));
#ifndef _WIN32
replace_string(&cfg.shell, "/bin/sh");
update_string(&cfg.shell_cmd_flag, "-c");
#else
replace_string(&cfg.shell, "cmd");
update_string(&cfg.shell_cmd_flag, "/C");
#endif
stats_update_shell_type(cfg.shell);
nlines = 0;
assert_success(process_cmd_output("tests", "cat list", NULL, 1, 0,
&line_handler, NULL));
assert_int_equal(1, nlines);
stats_update_shell_type("/bin/sh");
update_string(&cfg.shell, NULL);
update_string(&cfg.shell_cmd_flag, NULL);
assert_success(unlink("list"));
restore_cwd(saved_cwd);
}
TEST(input_redirection, IF(have_cat))
{
char *saved_cwd;
FILE *const f = fopen(SANDBOX_PATH "/list", "w+");
fprintf(f, "%s", "/a\n/b");
fflush(f);
saved_cwd = save_cwd();
assert_success(chdir(SANDBOX_PATH));
#ifndef _WIN32
replace_string(&cfg.shell, "/bin/sh");
update_string(&cfg.shell_cmd_flag, "-c");
#else
replace_string(&cfg.shell, "cmd");
update_string(&cfg.shell_cmd_flag, "/C");
#endif
stats_update_shell_type(cfg.shell);
nlines = 0;
assert_success(process_cmd_output("tests", "cat", f, 1, 0,
&line_handler, NULL));
assert_int_equal(2, nlines);
stats_update_shell_type("/bin/sh");
update_string(&cfg.shell, NULL);
update_string(&cfg.shell_cmd_flag, NULL);
fclose(f);
assert_success(unlink("list"));
restore_cwd(saved_cwd);
}
static void
line_handler(const char line[], void *arg)
{
++nlines;
}
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 filetype=c : */
|