File tests/commands/misc.c changed (mode: 100644) (index 7fc83c4cc..d70e5e26c) |
1 |
1 |
#include <stic.h> |
#include <stic.h> |
2 |
2 |
|
|
3 |
|
#include <unistd.h> /* chdir() rmdir() unlink() */ |
|
|
3 |
|
#include <unistd.h> /* chdir() rmdir() */ |
4 |
4 |
|
|
5 |
|
#include <limits.h> /* INT_MAX */ |
|
6 |
5 |
#include <stdio.h> /* remove() snprintf() */ |
#include <stdio.h> /* remove() snprintf() */ |
7 |
6 |
#include <string.h> /* strcpy() strdup() */ |
#include <string.h> /* strcpy() strdup() */ |
8 |
7 |
|
|
|
... |
... |
TEST(double_cd_uses_same_base_for_rel_paths) |
106 |
105 |
assert_true(paths_are_equal(rwin.curr_dir, path)); |
assert_true(paths_are_equal(rwin.curr_dir, path)); |
107 |
106 |
} |
} |
108 |
107 |
|
|
109 |
|
TEST(tr_extends_second_field) |
|
110 |
|
{ |
|
111 |
|
char path[PATH_MAX + 1]; |
|
112 |
|
|
|
113 |
|
assert_success(chdir(sandbox)); |
|
114 |
|
|
|
115 |
|
strcpy(lwin.curr_dir, sandbox); |
|
116 |
|
|
|
117 |
|
snprintf(path, sizeof(path), "%s/a b", sandbox); |
|
118 |
|
create_file(path); |
|
119 |
|
|
|
120 |
|
lwin.list_rows = 1; |
|
121 |
|
lwin.list_pos = 0; |
|
122 |
|
lwin.dir_entry = dynarray_cextend(NULL, |
|
123 |
|
lwin.list_rows*sizeof(*lwin.dir_entry)); |
|
124 |
|
lwin.dir_entry[0].name = strdup("a b"); |
|
125 |
|
lwin.dir_entry[0].origin = &lwin.curr_dir[0]; |
|
126 |
|
|
|
127 |
|
(void)cmds_dispatch("tr/ ?<>\\\\:*|\"/_", &lwin, CIT_COMMAND); |
|
128 |
|
|
|
129 |
|
snprintf(path, sizeof(path), "%s/a_b", sandbox); |
|
130 |
|
assert_success(remove(path)); |
|
131 |
|
} |
|
132 |
|
|
|
133 |
|
TEST(substitute_works) |
|
134 |
|
{ |
|
135 |
|
char path[PATH_MAX + 1]; |
|
136 |
|
|
|
137 |
|
assert_success(chdir(sandbox)); |
|
138 |
|
|
|
139 |
|
strcpy(lwin.curr_dir, sandbox); |
|
140 |
|
|
|
141 |
|
snprintf(path, sizeof(path), "%s/a b b", sandbox); |
|
142 |
|
create_file(path); |
|
143 |
|
snprintf(path, sizeof(path), "%s/B c", sandbox); |
|
144 |
|
create_file(path); |
|
145 |
|
|
|
146 |
|
lwin.list_rows = 2; |
|
147 |
|
lwin.list_pos = 0; |
|
148 |
|
lwin.dir_entry = dynarray_cextend(NULL, |
|
149 |
|
lwin.list_rows*sizeof(*lwin.dir_entry)); |
|
150 |
|
lwin.dir_entry[0].name = strdup("a b b"); |
|
151 |
|
lwin.dir_entry[0].origin = &lwin.curr_dir[0]; |
|
152 |
|
lwin.dir_entry[1].name = strdup("B c"); |
|
153 |
|
lwin.dir_entry[1].origin = &lwin.curr_dir[0]; |
|
154 |
|
|
|
155 |
|
(void)cmds_dispatch("%substitute/b/c/Iig", &lwin, CIT_COMMAND); |
|
156 |
|
|
|
157 |
|
snprintf(path, sizeof(path), "%s/a c c", sandbox); |
|
158 |
|
assert_success(remove(path)); |
|
159 |
|
snprintf(path, sizeof(path), "%s/c c", sandbox); |
|
160 |
|
assert_success(remove(path)); |
|
161 |
|
} |
|
162 |
|
|
|
163 |
|
TEST(chmod_works, IF(not_windows)) |
|
164 |
|
{ |
|
165 |
|
char path[PATH_MAX + 1]; |
|
166 |
|
|
|
167 |
|
assert_success(chdir(sandbox)); |
|
168 |
|
|
|
169 |
|
strcpy(lwin.curr_dir, sandbox); |
|
170 |
|
|
|
171 |
|
snprintf(path, sizeof(path), "%s/file1", sandbox); |
|
172 |
|
create_file(path); |
|
173 |
|
snprintf(path, sizeof(path), "%s/file2", sandbox); |
|
174 |
|
create_file(path); |
|
175 |
|
|
|
176 |
|
lwin.list_rows = 2; |
|
177 |
|
lwin.list_pos = 0; |
|
178 |
|
lwin.dir_entry = dynarray_cextend(NULL, |
|
179 |
|
lwin.list_rows*sizeof(*lwin.dir_entry)); |
|
180 |
|
lwin.dir_entry[0].name = strdup("file1"); |
|
181 |
|
lwin.dir_entry[0].origin = &lwin.curr_dir[0]; |
|
182 |
|
lwin.dir_entry[1].name = strdup("file2"); |
|
183 |
|
lwin.dir_entry[1].origin = &lwin.curr_dir[0]; |
|
184 |
|
|
|
185 |
|
(void)cmds_dispatch("1,2chmod +x", &lwin, CIT_COMMAND); |
|
186 |
|
|
|
187 |
|
populate_dir_list(&lwin, 1); |
|
188 |
|
assert_int_equal(FT_EXEC, lwin.dir_entry[0].type); |
|
189 |
|
assert_int_equal(FT_EXEC, lwin.dir_entry[1].type); |
|
190 |
|
|
|
191 |
|
snprintf(path, sizeof(path), "%s/file1", sandbox); |
|
192 |
|
assert_success(remove(path)); |
|
193 |
|
snprintf(path, sizeof(path), "%s/file2", sandbox); |
|
194 |
|
assert_success(remove(path)); |
|
195 |
|
} |
|
196 |
|
|
|
197 |
|
TEST(putting_files_works) |
|
198 |
|
{ |
|
199 |
|
char path[PATH_MAX + 1]; |
|
200 |
|
|
|
201 |
|
regs_init(); |
|
202 |
|
|
|
203 |
|
assert_success(os_mkdir(SANDBOX_PATH "/empty-dir", 0700)); |
|
204 |
|
assert_success(flist_load_tree(&lwin, sandbox, INT_MAX)); |
|
205 |
|
|
|
206 |
|
make_abs_path(path, sizeof(path), TEST_DATA_PATH, "read/binary-data", cwd); |
|
207 |
|
assert_success(regs_append(DEFAULT_REG_NAME, path)); |
|
208 |
|
lwin.list_pos = 1; |
|
209 |
|
|
|
210 |
|
assert_true(cmds_dispatch("put", &lwin, CIT_COMMAND) != 0); |
|
211 |
|
restore_cwd(saved_cwd); |
|
212 |
|
saved_cwd = save_cwd(); |
|
213 |
|
|
|
214 |
|
assert_success(unlink(SANDBOX_PATH "/empty-dir/binary-data")); |
|
215 |
|
assert_success(rmdir(SANDBOX_PATH "/empty-dir")); |
|
216 |
|
|
|
217 |
|
regs_reset(); |
|
218 |
|
} |
|
219 |
|
|
|
220 |
|
TEST(yank_works_with_ranges) |
|
221 |
|
{ |
|
222 |
|
char path[PATH_MAX + 1]; |
|
223 |
|
const reg_t *reg; |
|
224 |
|
|
|
225 |
|
regs_init(); |
|
226 |
|
|
|
227 |
|
flist_custom_start(&lwin, "test"); |
|
228 |
|
snprintf(path, sizeof(path), "%s/%s", test_data, "existing-files/a"); |
|
229 |
|
flist_custom_add(&lwin, path); |
|
230 |
|
assert_true(flist_custom_finish(&lwin, CV_REGULAR, 0) == 0); |
|
231 |
|
|
|
232 |
|
reg = regs_find(DEFAULT_REG_NAME); |
|
233 |
|
assert_non_null(reg); |
|
234 |
|
|
|
235 |
|
assert_int_equal(0, reg->nfiles); |
|
236 |
|
(void)cmds_dispatch("%yank", &lwin, CIT_COMMAND); |
|
237 |
|
assert_int_equal(1, reg->nfiles); |
|
238 |
|
|
|
239 |
|
regs_reset(); |
|
240 |
|
} |
|
241 |
|
|
|
242 |
108 |
TEST(symlinks_in_paths_are_not_resolved, IF(not_windows)) |
TEST(symlinks_in_paths_are_not_resolved, IF(not_windows)) |
243 |
109 |
{ |
{ |
244 |
110 |
char canonic_path[PATH_MAX + 1]; |
char canonic_path[PATH_MAX + 1]; |
|
... |
... |
TEST(grep_command, IF(not_windows)) |
321 |
187 |
opt_handlers_teardown(); |
opt_handlers_teardown(); |
322 |
188 |
} |
} |
323 |
189 |
|
|
324 |
|
TEST(touch) |
|
325 |
|
{ |
|
326 |
|
to_canonic_path(SANDBOX_PATH, cwd, lwin.curr_dir, sizeof(lwin.curr_dir)); |
|
327 |
|
(void)cmds_dispatch("touch file", &lwin, CIT_COMMAND); |
|
328 |
|
|
|
329 |
|
assert_success(remove(SANDBOX_PATH "/file")); |
|
330 |
|
} |
|
331 |
|
|
|
332 |
190 |
TEST(compare) |
TEST(compare) |
333 |
191 |
{ |
{ |
334 |
192 |
opt_handlers_setup(); |
opt_handlers_setup(); |
|
... |
... |
TEST(echo_without_arguments_prints_nothing) |
518 |
376 |
assert_string_equal("", ui_sb_last()); |
assert_string_equal("", ui_sb_last()); |
519 |
377 |
} |
} |
520 |
378 |
|
|
521 |
|
TEST(zero_count_is_rejected) |
|
522 |
|
{ |
|
523 |
|
const char *expected = "Count argument can't be zero"; |
|
524 |
|
|
|
525 |
|
ui_sb_msg(""); |
|
526 |
|
assert_failure(cmds_dispatch("delete a 0", &lwin, CIT_COMMAND)); |
|
527 |
|
assert_string_equal(expected, ui_sb_last()); |
|
528 |
|
|
|
529 |
|
ui_sb_msg(""); |
|
530 |
|
assert_failure(cmds_dispatch("yank a 0", &lwin, CIT_COMMAND)); |
|
531 |
|
assert_string_equal(expected, ui_sb_last()); |
|
532 |
|
} |
|
533 |
|
|
|
534 |
379 |
TEST(tree_command) |
TEST(tree_command) |
535 |
380 |
{ |
{ |
536 |
381 |
strcpy(lwin.curr_dir, sandbox); |
strcpy(lwin.curr_dir, sandbox); |
File tests/commands/misc_fops.c added (mode: 100644) (index 000000000..1e93800dd) |
|
1 |
|
#include <stic.h> |
|
2 |
|
|
|
3 |
|
#include <unistd.h> /* chdir() rmdir() unlink() */ |
|
4 |
|
|
|
5 |
|
#include <limits.h> /* INT_MAX */ |
|
6 |
|
#include <stdio.h> /* remove() snprintf() */ |
|
7 |
|
#include <string.h> /* strcpy() strdup() */ |
|
8 |
|
|
|
9 |
|
#include <test-utils.h> |
|
10 |
|
|
|
11 |
|
#include "../../src/compat/fs_limits.h" |
|
12 |
|
#include "../../src/compat/os.h" |
|
13 |
|
#include "../../src/ui/statusbar.h" |
|
14 |
|
#include "../../src/ui/ui.h" |
|
15 |
|
#include "../../src/utils/dynarray.h" |
|
16 |
|
#include "../../src/utils/fs.h" |
|
17 |
|
#include "../../src/utils/path.h" |
|
18 |
|
#include "../../src/cmd_core.h" |
|
19 |
|
#include "../../src/filelist.h" |
|
20 |
|
#include "../../src/registers.h" |
|
21 |
|
|
|
22 |
|
static char *saved_cwd; |
|
23 |
|
|
|
24 |
|
static char cwd[PATH_MAX + 1]; |
|
25 |
|
static char sandbox[PATH_MAX + 1]; |
|
26 |
|
|
|
27 |
|
SETUP_ONCE() |
|
28 |
|
{ |
|
29 |
|
assert_non_null(get_cwd(cwd, sizeof(cwd))); |
|
30 |
|
make_abs_path(sandbox, sizeof(sandbox), SANDBOX_PATH, "", cwd); |
|
31 |
|
} |
|
32 |
|
|
|
33 |
|
SETUP() |
|
34 |
|
{ |
|
35 |
|
view_setup(&lwin); |
|
36 |
|
view_setup(&rwin); |
|
37 |
|
|
|
38 |
|
curr_view = &lwin; |
|
39 |
|
other_view = &rwin; |
|
40 |
|
|
|
41 |
|
conf_setup(); |
|
42 |
|
undo_setup(); |
|
43 |
|
cmds_init(); |
|
44 |
|
|
|
45 |
|
saved_cwd = save_cwd(); |
|
46 |
|
} |
|
47 |
|
|
|
48 |
|
TEARDOWN() |
|
49 |
|
{ |
|
50 |
|
restore_cwd(saved_cwd); |
|
51 |
|
|
|
52 |
|
view_teardown(&lwin); |
|
53 |
|
view_teardown(&rwin); |
|
54 |
|
|
|
55 |
|
conf_teardown(); |
|
56 |
|
vle_cmds_reset(); |
|
57 |
|
undo_teardown(); |
|
58 |
|
} |
|
59 |
|
|
|
60 |
|
TEST(tr_extends_second_field) |
|
61 |
|
{ |
|
62 |
|
char path[PATH_MAX + 1]; |
|
63 |
|
|
|
64 |
|
assert_success(chdir(sandbox)); |
|
65 |
|
|
|
66 |
|
strcpy(lwin.curr_dir, sandbox); |
|
67 |
|
|
|
68 |
|
snprintf(path, sizeof(path), "%s/a b", sandbox); |
|
69 |
|
create_file(path); |
|
70 |
|
|
|
71 |
|
lwin.list_rows = 1; |
|
72 |
|
lwin.list_pos = 0; |
|
73 |
|
lwin.dir_entry = dynarray_cextend(NULL, |
|
74 |
|
lwin.list_rows*sizeof(*lwin.dir_entry)); |
|
75 |
|
lwin.dir_entry[0].name = strdup("a b"); |
|
76 |
|
lwin.dir_entry[0].origin = &lwin.curr_dir[0]; |
|
77 |
|
|
|
78 |
|
(void)cmds_dispatch("tr/ ?<>\\\\:*|\"/_", &lwin, CIT_COMMAND); |
|
79 |
|
|
|
80 |
|
snprintf(path, sizeof(path), "%s/a_b", sandbox); |
|
81 |
|
assert_success(remove(path)); |
|
82 |
|
} |
|
83 |
|
|
|
84 |
|
TEST(substitute_works) |
|
85 |
|
{ |
|
86 |
|
char path[PATH_MAX + 1]; |
|
87 |
|
|
|
88 |
|
assert_success(chdir(sandbox)); |
|
89 |
|
|
|
90 |
|
strcpy(lwin.curr_dir, sandbox); |
|
91 |
|
|
|
92 |
|
snprintf(path, sizeof(path), "%s/a b b", sandbox); |
|
93 |
|
create_file(path); |
|
94 |
|
snprintf(path, sizeof(path), "%s/B c", sandbox); |
|
95 |
|
create_file(path); |
|
96 |
|
|
|
97 |
|
lwin.list_rows = 2; |
|
98 |
|
lwin.list_pos = 0; |
|
99 |
|
lwin.dir_entry = dynarray_cextend(NULL, |
|
100 |
|
lwin.list_rows*sizeof(*lwin.dir_entry)); |
|
101 |
|
lwin.dir_entry[0].name = strdup("a b b"); |
|
102 |
|
lwin.dir_entry[0].origin = &lwin.curr_dir[0]; |
|
103 |
|
lwin.dir_entry[1].name = strdup("B c"); |
|
104 |
|
lwin.dir_entry[1].origin = &lwin.curr_dir[0]; |
|
105 |
|
|
|
106 |
|
(void)cmds_dispatch("%substitute/b/c/Iig", &lwin, CIT_COMMAND); |
|
107 |
|
|
|
108 |
|
snprintf(path, sizeof(path), "%s/a c c", sandbox); |
|
109 |
|
assert_success(remove(path)); |
|
110 |
|
snprintf(path, sizeof(path), "%s/c c", sandbox); |
|
111 |
|
assert_success(remove(path)); |
|
112 |
|
} |
|
113 |
|
|
|
114 |
|
TEST(chmod_works, IF(not_windows)) |
|
115 |
|
{ |
|
116 |
|
char path[PATH_MAX + 1]; |
|
117 |
|
|
|
118 |
|
assert_success(chdir(sandbox)); |
|
119 |
|
|
|
120 |
|
strcpy(lwin.curr_dir, sandbox); |
|
121 |
|
|
|
122 |
|
snprintf(path, sizeof(path), "%s/file1", sandbox); |
|
123 |
|
create_file(path); |
|
124 |
|
snprintf(path, sizeof(path), "%s/file2", sandbox); |
|
125 |
|
create_file(path); |
|
126 |
|
|
|
127 |
|
lwin.list_rows = 2; |
|
128 |
|
lwin.list_pos = 0; |
|
129 |
|
lwin.dir_entry = dynarray_cextend(NULL, |
|
130 |
|
lwin.list_rows*sizeof(*lwin.dir_entry)); |
|
131 |
|
lwin.dir_entry[0].name = strdup("file1"); |
|
132 |
|
lwin.dir_entry[0].origin = &lwin.curr_dir[0]; |
|
133 |
|
lwin.dir_entry[1].name = strdup("file2"); |
|
134 |
|
lwin.dir_entry[1].origin = &lwin.curr_dir[0]; |
|
135 |
|
|
|
136 |
|
(void)cmds_dispatch("1,2chmod +x", &lwin, CIT_COMMAND); |
|
137 |
|
|
|
138 |
|
populate_dir_list(&lwin, 1); |
|
139 |
|
assert_int_equal(FT_EXEC, lwin.dir_entry[0].type); |
|
140 |
|
assert_int_equal(FT_EXEC, lwin.dir_entry[1].type); |
|
141 |
|
|
|
142 |
|
snprintf(path, sizeof(path), "%s/file1", sandbox); |
|
143 |
|
assert_success(remove(path)); |
|
144 |
|
snprintf(path, sizeof(path), "%s/file2", sandbox); |
|
145 |
|
assert_success(remove(path)); |
|
146 |
|
} |
|
147 |
|
|
|
148 |
|
TEST(putting_files_works) |
|
149 |
|
{ |
|
150 |
|
char path[PATH_MAX + 1]; |
|
151 |
|
|
|
152 |
|
regs_init(); |
|
153 |
|
|
|
154 |
|
assert_success(os_mkdir(SANDBOX_PATH "/empty-dir", 0700)); |
|
155 |
|
assert_success(flist_load_tree(&lwin, sandbox, INT_MAX)); |
|
156 |
|
|
|
157 |
|
make_abs_path(path, sizeof(path), TEST_DATA_PATH, "read/binary-data", cwd); |
|
158 |
|
assert_success(regs_append(DEFAULT_REG_NAME, path)); |
|
159 |
|
lwin.list_pos = 1; |
|
160 |
|
|
|
161 |
|
assert_true(cmds_dispatch("put", &lwin, CIT_COMMAND) != 0); |
|
162 |
|
restore_cwd(saved_cwd); |
|
163 |
|
saved_cwd = save_cwd(); |
|
164 |
|
|
|
165 |
|
assert_success(unlink(SANDBOX_PATH "/empty-dir/binary-data")); |
|
166 |
|
assert_success(rmdir(SANDBOX_PATH "/empty-dir")); |
|
167 |
|
|
|
168 |
|
regs_reset(); |
|
169 |
|
} |
|
170 |
|
|
|
171 |
|
TEST(yank_works_with_ranges) |
|
172 |
|
{ |
|
173 |
|
char path[PATH_MAX + 1]; |
|
174 |
|
const reg_t *reg; |
|
175 |
|
|
|
176 |
|
regs_init(); |
|
177 |
|
|
|
178 |
|
flist_custom_start(&lwin, "test"); |
|
179 |
|
make_abs_path(path, sizeof(path), TEST_DATA_PATH, "existing-files/a", cwd); |
|
180 |
|
flist_custom_add(&lwin, path); |
|
181 |
|
assert_true(flist_custom_finish(&lwin, CV_REGULAR, 0) == 0); |
|
182 |
|
|
|
183 |
|
reg = regs_find(DEFAULT_REG_NAME); |
|
184 |
|
assert_non_null(reg); |
|
185 |
|
|
|
186 |
|
assert_int_equal(0, reg->nfiles); |
|
187 |
|
(void)cmds_dispatch("%yank", &lwin, CIT_COMMAND); |
|
188 |
|
assert_int_equal(1, reg->nfiles); |
|
189 |
|
|
|
190 |
|
regs_reset(); |
|
191 |
|
} |
|
192 |
|
|
|
193 |
|
TEST(touch) |
|
194 |
|
{ |
|
195 |
|
to_canonic_path(SANDBOX_PATH, cwd, lwin.curr_dir, sizeof(lwin.curr_dir)); |
|
196 |
|
(void)cmds_dispatch("touch file", &lwin, CIT_COMMAND); |
|
197 |
|
|
|
198 |
|
assert_success(remove(SANDBOX_PATH "/file")); |
|
199 |
|
} |
|
200 |
|
|
|
201 |
|
TEST(zero_count_is_rejected) |
|
202 |
|
{ |
|
203 |
|
const char *expected = "Count argument can't be zero"; |
|
204 |
|
|
|
205 |
|
ui_sb_msg(""); |
|
206 |
|
assert_failure(cmds_dispatch("delete a 0", &lwin, CIT_COMMAND)); |
|
207 |
|
assert_string_equal(expected, ui_sb_last()); |
|
208 |
|
|
|
209 |
|
ui_sb_msg(""); |
|
210 |
|
assert_failure(cmds_dispatch("yank a 0", &lwin, CIT_COMMAND)); |
|
211 |
|
assert_string_equal(expected, ui_sb_last()); |
|
212 |
|
} |
|
213 |
|
|
|
214 |
|
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ |
|
215 |
|
/* vim: set cinoptions+=t0 filetype=c : */ |