xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit c56d8e380c3a19fc85863e65e6c966abe7bcc105

Extract tests/ior/cp-symlinks.c
These tests require more space as new ones are coming.
Author: xaizek
Author date (UTC): 2026-02-13 09:46
Committer name: xaizek
Committer date (UTC): 2026-02-19 09:45
Parent(s): 975fb656f448868caf91bd1e88c96d4bd8455c27
Signing key: 99DC5E4DB05F6BE2
Tree: c62c1738c13398d3ba97ae03794b05383ee02c8b
File Lines added Lines deleted
tests/ior/cp-symlinks.c 244 0
tests/ior/cp.c 0 230
File tests/ior/cp-symlinks.c added (mode: 100644) (index 000000000..cdf3de7d5)
1 #include <stic.h>
2
3 #include <sys/stat.h> /* chmod() */
4
5 #include <test-utils.h>
6
7 #include "../../src/compat/fs_limits.h"
8 #include "../../src/io/iop.h"
9 #include "../../src/io/ior.h"
10 #include "../../src/utils/fs.h"
11
12 #include "utils.h"
13
14 /* Creating symbolic links on Windows requires administrator rights. */
15 TEST(symlink_to_file_is_symlink_after_copy, IF(not_windows))
16 {
17 {
18 io_args_t args = {
19 .arg1.path = TEST_DATA_PATH "/read/two-lines",
20 .arg2.target = SANDBOX_PATH "/sym-link",
21 };
22 ioe_errlst_init(&args.result.errors);
23
24 assert_int_equal(IO_RES_SUCCEEDED, iop_ln(&args));
25 assert_int_equal(0, args.result.errors.error_count);
26 }
27
28 assert_true(is_symlink(SANDBOX_PATH "/sym-link"));
29
30 {
31 io_args_t args = {
32 .arg1.src = SANDBOX_PATH "/sym-link",
33 .arg2.dst = SANDBOX_PATH "/sym-link-copy",
34 };
35 ioe_errlst_init(&args.result.errors);
36
37 assert_int_equal(IO_RES_SUCCEEDED, ior_cp(&args));
38 assert_int_equal(0, args.result.errors.error_count);
39 }
40
41 assert_true(is_symlink(SANDBOX_PATH "/sym-link"));
42 assert_true(is_symlink(SANDBOX_PATH "/sym-link-copy"));
43
44 {
45 io_args_t args = {
46 .arg1.path = SANDBOX_PATH "/sym-link",
47 };
48 ioe_errlst_init(&args.result.errors);
49
50 assert_int_equal(IO_RES_SUCCEEDED, iop_rmfile(&args));
51 assert_int_equal(0, args.result.errors.error_count);
52 }
53
54 {
55 io_args_t args = {
56 .arg1.path = SANDBOX_PATH "/sym-link-copy",
57 };
58 ioe_errlst_init(&args.result.errors);
59
60 assert_int_equal(IO_RES_SUCCEEDED, iop_rmfile(&args));
61 assert_int_equal(0, args.result.errors.error_count);
62 }
63 }
64
65 /* Creating symbolic links on Windows requires administrator rights. */
66 TEST(symlink_to_dir_is_symlink_after_copy, IF(not_windows))
67 {
68 {
69 io_args_t args = {
70 .arg1.path = TEST_DATA_PATH "/read",
71 .arg2.target = SANDBOX_PATH "/sym-link",
72 };
73 ioe_errlst_init(&args.result.errors);
74
75 assert_int_equal(IO_RES_SUCCEEDED, iop_ln(&args));
76 assert_int_equal(0, args.result.errors.error_count);
77 }
78
79 assert_true(is_symlink(SANDBOX_PATH "/sym-link"));
80
81 {
82 io_args_t args = {
83 .arg1.src = SANDBOX_PATH "/sym-link",
84 .arg2.dst = SANDBOX_PATH "/sym-link-copy",
85 };
86 ioe_errlst_init(&args.result.errors);
87
88 assert_int_equal(IO_RES_SUCCEEDED, ior_cp(&args));
89 assert_int_equal(0, args.result.errors.error_count);
90 }
91
92 assert_true(is_symlink(SANDBOX_PATH "/sym-link"));
93 assert_true(is_symlink(SANDBOX_PATH "/sym-link-copy"));
94
95 {
96 io_args_t args = {
97 .arg1.path = SANDBOX_PATH "/sym-link",
98 };
99 ioe_errlst_init(&args.result.errors);
100
101 assert_int_equal(IO_RES_SUCCEEDED, iop_rmfile(&args));
102 assert_int_equal(0, args.result.errors.error_count);
103 }
104
105 {
106 io_args_t args = {
107 .arg1.path = SANDBOX_PATH "/sym-link-copy",
108 };
109 ioe_errlst_init(&args.result.errors);
110
111 assert_int_equal(IO_RES_SUCCEEDED, iop_rmfile(&args));
112 assert_int_equal(0, args.result.errors.error_count);
113 }
114 }
115
116 /* Creating symbolic links on Windows requires administrator rights. */
117 TEST(symlink_to_dir_is_dir_after_copy, IF(not_windows))
118 {
119 {
120 char path[PATH_MAX + 1];
121 io_args_t args = {
122 .arg1.path = path,
123 .arg2.target = SANDBOX_PATH "/sym-link",
124 };
125 ioe_errlst_init(&args.result.errors);
126
127 make_abs_path(path, sizeof(path), TEST_DATA_PATH, "read", NULL);
128 assert_int_equal(IO_RES_SUCCEEDED, iop_ln(&args));
129 assert_int_equal(0, args.result.errors.error_count);
130 }
131
132 assert_true(is_symlink(SANDBOX_PATH "/sym-link"));
133
134 {
135 io_args_t args = {
136 .arg1.src = SANDBOX_PATH "/sym-link",
137 .arg2.dst = SANDBOX_PATH "/sym-link-copy",
138 .arg4.deep_copying = 1,
139 };
140 ioe_errlst_init(&args.result.errors);
141
142 assert_int_equal(IO_RES_SUCCEEDED, ior_cp(&args));
143 assert_int_equal(0, args.result.errors.error_count);
144 }
145
146 assert_true(is_symlink(SANDBOX_PATH "/sym-link"));
147 assert_false(is_symlink(SANDBOX_PATH "/sym-link-copy"));
148 assert_true(is_dir(SANDBOX_PATH "/sym-link-copy"));
149
150 {
151 io_args_t args = {
152 .arg1.path = SANDBOX_PATH "/sym-link",
153 };
154 ioe_errlst_init(&args.result.errors);
155
156 assert_int_equal(IO_RES_SUCCEEDED, iop_rmfile(&args));
157 assert_int_equal(0, args.result.errors.error_count);
158 }
159
160 /* Needed to be able to remove files from it. */
161 assert_success(chmod(SANDBOX_PATH "/sym-link-copy", 0700));
162
163 {
164 io_args_t args = {
165 .arg1.path = SANDBOX_PATH "/sym-link-copy",
166 };
167 ioe_errlst_init(&args.result.errors);
168
169 assert_int_equal(IO_RES_SUCCEEDED, ior_rm(&args));
170 assert_int_equal(0, args.result.errors.error_count);
171 }
172 }
173
174 /* Creating symbolic links on Windows requires administrator rights. */
175 TEST(nested_symlink_to_dir_is_dir_after_copy, IF(not_windows))
176 {
177 {
178 io_args_t args = {
179 .arg1.path = SANDBOX_PATH "/dir",
180 .arg3.mode = 0700,
181 };
182 ioe_errlst_init(&args.result.errors);
183
184 assert_int_equal(IO_RES_SUCCEEDED, iop_mkdir(&args));
185 assert_int_equal(0, args.result.errors.error_count);
186 }
187
188 {
189 char path[PATH_MAX + 1];
190 io_args_t args = {
191 .arg1.path = path,
192 .arg2.target = SANDBOX_PATH "/dir/sym-link",
193 };
194 ioe_errlst_init(&args.result.errors);
195
196 make_abs_path(path, sizeof(path), TEST_DATA_PATH, "read", NULL);
197 assert_int_equal(IO_RES_SUCCEEDED, iop_ln(&args));
198 assert_int_equal(0, args.result.errors.error_count);
199 }
200
201 assert_true(is_symlink(SANDBOX_PATH "/dir/sym-link"));
202
203 {
204 io_args_t args = {
205 .arg1.src = SANDBOX_PATH "/dir",
206 .arg2.dst = SANDBOX_PATH "/dir-copy",
207 .arg4.deep_copying = 1,
208 };
209 ioe_errlst_init(&args.result.errors);
210
211 assert_int_equal(IO_RES_SUCCEEDED, ior_cp(&args));
212 assert_int_equal(0, args.result.errors.error_count);
213 }
214
215 assert_true(is_symlink(SANDBOX_PATH "/dir/sym-link"));
216 assert_false(is_symlink(SANDBOX_PATH "/dir-copy/sym-link"));
217 assert_true(is_dir(SANDBOX_PATH "/dir-copy/sym-link"));
218
219 {
220 io_args_t args = {
221 .arg1.path = SANDBOX_PATH "/dir",
222 };
223 ioe_errlst_init(&args.result.errors);
224
225 assert_int_equal(IO_RES_SUCCEEDED, ior_rm(&args));
226 assert_int_equal(0, args.result.errors.error_count);
227 }
228
229 /* Needed to be able to remove files from it. */
230 assert_success(chmod(SANDBOX_PATH "/dir-copy/sym-link", 0700));
231
232 {
233 io_args_t args = {
234 .arg1.path = SANDBOX_PATH "/dir-copy",
235 };
236 ioe_errlst_init(&args.result.errors);
237
238 assert_int_equal(IO_RES_SUCCEEDED, ior_rm(&args));
239 assert_int_equal(0, args.result.errors.error_count);
240 }
241 }
242
243 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
244 /* vim: set cinoptions+=t0 filetype=c : */
File tests/ior/cp.c changed (mode: 100644) (index 0829b494f..cbee70599)
6 6
7 7 #include <test-utils.h> #include <test-utils.h>
8 8
9 #include "../../src/compat/fs_limits.h"
10 9 #include "../../src/compat/os.h" #include "../../src/compat/os.h"
11 10 #include "../../src/io/iop.h" #include "../../src/io/iop.h"
12 11 #include "../../src/io/ior.h" #include "../../src/io/ior.h"
 
... ... TEST(permissions_are_set_in_correct_order)
551 550 } }
552 551 } }
553 552
554 /* Creating symbolic links on Windows requires administrator rights. */
555 TEST(symlink_to_file_is_symlink_after_copy, IF(not_windows))
556 {
557 {
558 io_args_t args = {
559 .arg1.path = TEST_DATA_PATH "/read/two-lines",
560 .arg2.target = SANDBOX_PATH "/sym-link",
561 };
562 ioe_errlst_init(&args.result.errors);
563
564 assert_int_equal(IO_RES_SUCCEEDED, iop_ln(&args));
565 assert_int_equal(0, args.result.errors.error_count);
566 }
567
568 assert_true(is_symlink(SANDBOX_PATH "/sym-link"));
569
570 {
571 io_args_t args = {
572 .arg1.src = SANDBOX_PATH "/sym-link",
573 .arg2.dst = SANDBOX_PATH "/sym-link-copy",
574 };
575 ioe_errlst_init(&args.result.errors);
576
577 assert_int_equal(IO_RES_SUCCEEDED, ior_cp(&args));
578 assert_int_equal(0, args.result.errors.error_count);
579 }
580
581 assert_true(is_symlink(SANDBOX_PATH "/sym-link"));
582 assert_true(is_symlink(SANDBOX_PATH "/sym-link-copy"));
583
584 {
585 io_args_t args = {
586 .arg1.path = SANDBOX_PATH "/sym-link",
587 };
588 ioe_errlst_init(&args.result.errors);
589
590 assert_int_equal(IO_RES_SUCCEEDED, iop_rmfile(&args));
591 assert_int_equal(0, args.result.errors.error_count);
592 }
593
594 {
595 io_args_t args = {
596 .arg1.path = SANDBOX_PATH "/sym-link-copy",
597 };
598 ioe_errlst_init(&args.result.errors);
599
600 assert_int_equal(IO_RES_SUCCEEDED, iop_rmfile(&args));
601 assert_int_equal(0, args.result.errors.error_count);
602 }
603 }
604
605 /* Creating symbolic links on Windows requires administrator rights. */
606 TEST(symlink_to_dir_is_symlink_after_copy, IF(not_windows))
607 {
608 {
609 io_args_t args = {
610 .arg1.path = TEST_DATA_PATH "/read",
611 .arg2.target = SANDBOX_PATH "/sym-link",
612 };
613 ioe_errlst_init(&args.result.errors);
614
615 assert_int_equal(IO_RES_SUCCEEDED, iop_ln(&args));
616 assert_int_equal(0, args.result.errors.error_count);
617 }
618
619 assert_true(is_symlink(SANDBOX_PATH "/sym-link"));
620
621 {
622 io_args_t args = {
623 .arg1.src = SANDBOX_PATH "/sym-link",
624 .arg2.dst = SANDBOX_PATH "/sym-link-copy",
625 };
626 ioe_errlst_init(&args.result.errors);
627
628 assert_int_equal(IO_RES_SUCCEEDED, ior_cp(&args));
629 assert_int_equal(0, args.result.errors.error_count);
630 }
631
632 assert_true(is_symlink(SANDBOX_PATH "/sym-link"));
633 assert_true(is_symlink(SANDBOX_PATH "/sym-link-copy"));
634
635 {
636 io_args_t args = {
637 .arg1.path = SANDBOX_PATH "/sym-link",
638 };
639 ioe_errlst_init(&args.result.errors);
640
641 assert_int_equal(IO_RES_SUCCEEDED, iop_rmfile(&args));
642 assert_int_equal(0, args.result.errors.error_count);
643 }
644
645 {
646 io_args_t args = {
647 .arg1.path = SANDBOX_PATH "/sym-link-copy",
648 };
649 ioe_errlst_init(&args.result.errors);
650
651 assert_int_equal(IO_RES_SUCCEEDED, iop_rmfile(&args));
652 assert_int_equal(0, args.result.errors.error_count);
653 }
654 }
655
656 /* Creating symbolic links on Windows requires administrator rights. */
657 TEST(symlink_to_dir_is_dir_after_copy, IF(not_windows))
658 {
659 {
660 char path[PATH_MAX + 1];
661 io_args_t args = {
662 .arg1.path = path,
663 .arg2.target = SANDBOX_PATH "/sym-link",
664 };
665 ioe_errlst_init(&args.result.errors);
666
667 make_abs_path(path, sizeof(path), TEST_DATA_PATH, "read", NULL);
668 assert_int_equal(IO_RES_SUCCEEDED, iop_ln(&args));
669 assert_int_equal(0, args.result.errors.error_count);
670 }
671
672 assert_true(is_symlink(SANDBOX_PATH "/sym-link"));
673
674 {
675 io_args_t args = {
676 .arg1.src = SANDBOX_PATH "/sym-link",
677 .arg2.dst = SANDBOX_PATH "/sym-link-copy",
678 .arg4.deep_copying = 1,
679 };
680 ioe_errlst_init(&args.result.errors);
681
682 assert_int_equal(IO_RES_SUCCEEDED, ior_cp(&args));
683 assert_int_equal(0, args.result.errors.error_count);
684 }
685
686 assert_true(is_symlink(SANDBOX_PATH "/sym-link"));
687 assert_false(is_symlink(SANDBOX_PATH "/sym-link-copy"));
688 assert_true(is_dir(SANDBOX_PATH "/sym-link-copy"));
689
690 {
691 io_args_t args = {
692 .arg1.path = SANDBOX_PATH "/sym-link",
693 };
694 ioe_errlst_init(&args.result.errors);
695
696 assert_int_equal(IO_RES_SUCCEEDED, iop_rmfile(&args));
697 assert_int_equal(0, args.result.errors.error_count);
698 }
699
700 /* Needed to be able to remove files from it. */
701 assert_success(chmod(SANDBOX_PATH "/sym-link-copy", 0700));
702
703 {
704 io_args_t args = {
705 .arg1.path = SANDBOX_PATH "/sym-link-copy",
706 };
707 ioe_errlst_init(&args.result.errors);
708
709 assert_int_equal(IO_RES_SUCCEEDED, ior_rm(&args));
710 assert_int_equal(0, args.result.errors.error_count);
711 }
712 }
713
714 /* Creating symbolic links on Windows requires administrator rights. */
715 TEST(nested_symlink_to_dir_is_dir_after_copy, IF(not_windows))
716 {
717 {
718 io_args_t args = {
719 .arg1.path = SANDBOX_PATH "/dir",
720 .arg3.mode = 0700,
721 };
722 ioe_errlst_init(&args.result.errors);
723
724 assert_int_equal(IO_RES_SUCCEEDED, iop_mkdir(&args));
725 assert_int_equal(0, args.result.errors.error_count);
726 }
727
728 {
729 char path[PATH_MAX + 1];
730 io_args_t args = {
731 .arg1.path = path,
732 .arg2.target = SANDBOX_PATH "/dir/sym-link",
733 };
734 ioe_errlst_init(&args.result.errors);
735
736 make_abs_path(path, sizeof(path), TEST_DATA_PATH, "read", NULL);
737 assert_int_equal(IO_RES_SUCCEEDED, iop_ln(&args));
738 assert_int_equal(0, args.result.errors.error_count);
739 }
740
741 assert_true(is_symlink(SANDBOX_PATH "/dir/sym-link"));
742
743 {
744 io_args_t args = {
745 .arg1.src = SANDBOX_PATH "/dir",
746 .arg2.dst = SANDBOX_PATH "/dir-copy",
747 .arg4.deep_copying = 1,
748 };
749 ioe_errlst_init(&args.result.errors);
750
751 assert_int_equal(IO_RES_SUCCEEDED, ior_cp(&args));
752 assert_int_equal(0, args.result.errors.error_count);
753 }
754
755 assert_true(is_symlink(SANDBOX_PATH "/dir/sym-link"));
756 assert_false(is_symlink(SANDBOX_PATH "/dir-copy/sym-link"));
757 assert_true(is_dir(SANDBOX_PATH "/dir-copy/sym-link"));
758
759 {
760 io_args_t args = {
761 .arg1.path = SANDBOX_PATH "/dir",
762 };
763 ioe_errlst_init(&args.result.errors);
764
765 assert_int_equal(IO_RES_SUCCEEDED, ior_rm(&args));
766 assert_int_equal(0, args.result.errors.error_count);
767 }
768
769 /* Needed to be able to remove files from it. */
770 assert_success(chmod(SANDBOX_PATH "/dir-copy/sym-link", 0700));
771
772 {
773 io_args_t args = {
774 .arg1.path = SANDBOX_PATH "/dir-copy",
775 };
776 ioe_errlst_init(&args.result.errors);
777
778 assert_int_equal(IO_RES_SUCCEEDED, ior_rm(&args));
779 assert_int_equal(0, args.result.errors.error_count);
780 }
781 }
782
783 553 static int static int
784 554 confirm_overwrite(io_args_t *args, const char src[], const char dst[]) confirm_overwrite(io_args_t *args, const char src[], const char dst[])
785 555 { {
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master