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 6d1196088bd34583dd62b17ec1ea6ddb896fcd0e

Extract tests/commands/misc.c fixture
Out of tests/commands/misc.c
Author: xaizek
Author date (UTC): 2023-03-16 16:31
Committer name: xaizek
Committer date (UTC): 2023-03-16 16:31
Parent(s): e6c8ed740e1767d0e19f157a38f90475e949ac13
Signing key: 99DC5E4DB05F6BE2
Tree: 71f88bf0695f3ed1534b5c7f0a005e352f236f48
File Lines added Lines deleted
tests/commands/misc.c 0 70
tests/commands/regedit.c 106 0
File tests/commands/misc.c changed (mode: 100644) (index 3693b9a70..ddeca6ccb)
... ... TEST(locate_command)
755 755 assert_string_equal("Nothing to repeat", ui_sb_last()); assert_string_equal("Nothing to repeat", ui_sb_last());
756 756 } }
757 757
758 TEST(regedit, IF(not_windows))
759 {
760 create_executable(SANDBOX_PATH "/script");
761 make_file(SANDBOX_PATH "/script",
762 "#!/bin/sh\n"
763 "sed 's/from/to/' < \"$3\" > \"$3_out\"\n"
764 "mv \"$3_out\" \"$3\"\n");
765
766 char vi_cmd[PATH_MAX + 1];
767 make_abs_path(vi_cmd, sizeof(vi_cmd), SANDBOX_PATH, "script", NULL);
768 update_string(&cfg.vi_command, vi_cmd);
769
770 ui_sb_msg("");
771 assert_failure(cmds_dispatch("regedit abc", &lwin, CIT_COMMAND));
772 assert_string_equal("Invalid argument: abc", ui_sb_last());
773 assert_failure(cmds_dispatch("regedit _", &lwin, CIT_COMMAND));
774 assert_string_equal("Cannot modify blackhole register.", ui_sb_last());
775 assert_failure(cmds_dispatch("regedit %", &lwin, CIT_COMMAND));
776 assert_string_equal("Register with given name does not exist.", ui_sb_last());
777
778 regs_append('a', "/path/before");
779 regs_append('a', "/path/from-1");
780 regs_append('a', "/path/from-2");
781 regs_append('a', "/path/to-2");
782 regs_append('a', "/path/this-was-after");
783
784 assert_success(cmds_dispatch("regedit a", &lwin, CIT_COMMAND));
785
786 /* Result should be sorted and without duplicates. */
787 const reg_t *reg = regs_find('a');
788 assert_int_equal(4, reg->nfiles);
789 assert_string_equal("/path/before", reg->files[0]);
790 assert_string_equal("/path/this-was-after", reg->files[1]);
791 assert_string_equal("/path/to-1", reg->files[2]);
792 assert_string_equal("/path/to-2", reg->files[3]);
793
794 remove_file(SANDBOX_PATH "/script");
795 }
796
797 TEST(regedit_normalizes_paths, IF(not_windows))
798 {
799 create_executable(SANDBOX_PATH "/script");
800 make_file(SANDBOX_PATH "/script",
801 "#!/bin/sh\n"
802 "sed 's/from/to/' < \"$3\" > \"$3_out\"\n"
803 "mv \"$3_out\" \"$3\"\n");
804
805 char vi_cmd[PATH_MAX + 1];
806 make_abs_path(vi_cmd, sizeof(vi_cmd), SANDBOX_PATH, "script", NULL);
807 update_string(&cfg.vi_command, vi_cmd);
808
809 strcpy(lwin.curr_dir, sandbox);
810
811 regs_append(DEFAULT_REG_NAME, "/abs/path/from-1");
812 regs_append(DEFAULT_REG_NAME, "from-2");
813
814 assert_success(cmds_dispatch("regedit", &lwin, CIT_COMMAND));
815
816 /* Result should contain only absolute paths. */
817 const reg_t *reg = regs_find(DEFAULT_REG_NAME);
818 assert_int_equal(2, reg->nfiles);
819 int rel_idx = (ends_with(reg->files[0], "/to-2") ? 0 : 1);
820 assert_string_equal("/abs/path/to-1", reg->files[1 - rel_idx]);
821 assert_string_ends_with("/to-2", reg->files[rel_idx]);
822 assert_true(is_path_absolute(reg->files[0]));
823 assert_true(is_path_absolute(reg->files[1]));
824
825 remove_file(SANDBOX_PATH "/script");
826 }
827
828 758 static void static void
829 759 strings_list_is(const strlist_t expected, const strlist_t actual) strings_list_is(const strlist_t expected, const strlist_t actual)
830 760 { {
File tests/commands/regedit.c added (mode: 100644) (index 000000000..90a31a2c2)
1 #include <stic.h>
2
3 #include <test-utils.h>
4
5 #include "../../src/cfg/config.h"
6 #include "../../src/compat/fs_limits.h"
7 #include "../../src/engine/cmds.h"
8 #include "../../src/ui/statusbar.h"
9 #include "../../src/ui/ui.h"
10 #include "../../src/utils/path.h"
11 #include "../../src/utils/str.h"
12 #include "../../src/cmd_core.h"
13 #include "../../src/registers.h"
14
15 SETUP()
16 {
17 view_setup(&lwin);
18 curr_view = &lwin;
19
20 conf_setup();
21 cmds_init();
22 regs_init();
23 }
24
25 TEARDOWN()
26 {
27 view_teardown(&lwin);
28 curr_view = NULL;
29
30 conf_teardown();
31 vle_cmds_reset();
32 regs_reset();
33 }
34
35 TEST(regedit, IF(not_windows))
36 {
37 create_executable(SANDBOX_PATH "/script");
38 make_file(SANDBOX_PATH "/script",
39 "#!/bin/sh\n"
40 "sed 's/from/to/' < \"$3\" > \"$3_out\"\n"
41 "mv \"$3_out\" \"$3\"\n");
42
43 char vi_cmd[PATH_MAX + 1];
44 make_abs_path(vi_cmd, sizeof(vi_cmd), SANDBOX_PATH, "script", NULL);
45 update_string(&cfg.vi_command, vi_cmd);
46
47 ui_sb_msg("");
48 assert_failure(cmds_dispatch("regedit abc", &lwin, CIT_COMMAND));
49 assert_string_equal("Invalid argument: abc", ui_sb_last());
50 assert_failure(cmds_dispatch("regedit _", &lwin, CIT_COMMAND));
51 assert_string_equal("Cannot modify blackhole register.", ui_sb_last());
52 assert_failure(cmds_dispatch("regedit %", &lwin, CIT_COMMAND));
53 assert_string_equal("Register with given name does not exist.", ui_sb_last());
54
55 regs_append('a', "/path/before");
56 regs_append('a', "/path/from-1");
57 regs_append('a', "/path/from-2");
58 regs_append('a', "/path/to-2");
59 regs_append('a', "/path/this-was-after");
60
61 assert_success(cmds_dispatch("regedit a", &lwin, CIT_COMMAND));
62
63 /* Result should be sorted and without duplicates. */
64 const reg_t *reg = regs_find('a');
65 assert_int_equal(4, reg->nfiles);
66 assert_string_equal("/path/before", reg->files[0]);
67 assert_string_equal("/path/this-was-after", reg->files[1]);
68 assert_string_equal("/path/to-1", reg->files[2]);
69 assert_string_equal("/path/to-2", reg->files[3]);
70
71 remove_file(SANDBOX_PATH "/script");
72 }
73
74 TEST(regedit_normalizes_paths, IF(not_windows))
75 {
76 create_executable(SANDBOX_PATH "/script");
77 make_file(SANDBOX_PATH "/script",
78 "#!/bin/sh\n"
79 "sed 's/from/to/' < \"$3\" > \"$3_out\"\n"
80 "mv \"$3_out\" \"$3\"\n");
81
82 char vi_cmd[PATH_MAX + 1];
83 make_abs_path(vi_cmd, sizeof(vi_cmd), SANDBOX_PATH, "script", NULL);
84 update_string(&cfg.vi_command, vi_cmd);
85
86 make_abs_path(lwin.curr_dir, sizeof(lwin.curr_dir), SANDBOX_PATH, "", NULL);
87
88 regs_append(DEFAULT_REG_NAME, "/abs/path/from-1");
89 regs_append(DEFAULT_REG_NAME, "from-2");
90
91 assert_success(cmds_dispatch("regedit", &lwin, CIT_COMMAND));
92
93 /* Result should contain only absolute paths. */
94 const reg_t *reg = regs_find(DEFAULT_REG_NAME);
95 assert_int_equal(2, reg->nfiles);
96 int rel_idx = (ends_with(reg->files[0], "/to-2") ? 0 : 1);
97 assert_string_equal("/abs/path/to-1", reg->files[1 - rel_idx]);
98 assert_string_ends_with("/to-2", reg->files[rel_idx]);
99 assert_true(is_path_absolute(reg->files[0]));
100 assert_true(is_path_absolute(reg->files[1]));
101
102 remove_file(SANDBOX_PATH "/script");
103 }
104
105 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
106 /* vim: set cinoptions+=t0 filetype=c : */
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