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 2485b506d3835447ca211397b365370418e189f7

Extract tests/commands/goto.c
Out of tests/commands/misc.c which got big again.
Author: xaizek
Author date (UTC): 2024-10-17 12:33
Committer name: xaizek
Committer date (UTC): 2024-10-17 21:14
Parent(s): db4eb727527bed8f4b25ba93c1ce18e3ede21762
Signing key: 99DC5E4DB05F6BE2
Tree: c49f901c866f9603e7a58ac1b2c8555a171c3d1f
File Lines added Lines deleted
tests/commands/goto.c 69 0
tests/commands/misc.c 1 26
File tests/commands/goto.c added (mode: 100644) (index 000000000..93f29076d)
1 #include <stic.h>
2
3 #include <stdio.h> /* snprintf() */
4
5 #include <test-utils.h>
6
7 #include "../../src/compat/fs_limits.h"
8 #include "../../src/ui/ui.h"
9 #include "../../src/utils/fs.h"
10 #include "../../src/cmd_core.h"
11 #include "../../src/filelist.h"
12
13 static char test_data[PATH_MAX + 1];
14
15 SETUP_ONCE()
16 {
17 make_abs_path(test_data, sizeof(test_data), TEST_DATA_PATH, "", NULL);
18 }
19
20 SETUP()
21 {
22 view_setup(&lwin);
23 view_setup(&rwin);
24
25 curr_view = &lwin;
26 other_view = &rwin;
27
28 conf_setup();
29 undo_setup();
30 cmds_init();
31 }
32
33 TEARDOWN()
34 {
35 view_teardown(&lwin);
36 view_teardown(&rwin);
37
38 conf_teardown();
39 vle_cmds_reset();
40 undo_teardown();
41 }
42
43 TEST(goto_navigates)
44 {
45 assert_failure(cmds_dispatch("goto /", &lwin, CIT_COMMAND));
46 assert_failure(cmds_dispatch("goto /no-such-path", &lwin, CIT_COMMAND));
47
48 char cmd[PATH_MAX*2];
49 snprintf(cmd, sizeof(cmd), "goto %s/compare", test_data);
50 assert_success(cmds_dispatch(cmd, &lwin, CIT_COMMAND));
51 assert_true(paths_are_same(lwin.curr_dir, test_data));
52 assert_string_equal("compare", get_current_file_name(&lwin));
53
54 assert_success(cmds_dispatch("goto tree", &lwin, CIT_COMMAND));
55 assert_true(paths_are_same(lwin.curr_dir, test_data));
56 assert_string_equal("tree", get_current_file_name(&lwin));
57 }
58
59 TEST(goto_normalizes_slashes, IF(windows))
60 {
61 char cmd[PATH_MAX*2];
62 snprintf(cmd, sizeof(cmd), "goto %s\\\\compare", test_data);
63 assert_success(cmds_dispatch(cmd, &lwin, CIT_COMMAND));
64 assert_true(paths_are_same(lwin.curr_dir, test_data));
65 assert_string_equal("compare", get_current_file_name(&lwin));
66 }
67
68 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
69 /* vim: set cinoptions+=t0 filetype=c : */
File tests/commands/misc.c changed (mode: 100644) (index 31410be78..4e20417a8)
3 3 #include <unistd.h> /* chdir() rmdir() unlink() */ #include <unistd.h> /* chdir() rmdir() unlink() */
4 4
5 5 #include <limits.h> /* INT_MAX */ #include <limits.h> /* INT_MAX */
6 #include <stdio.h> /* remove() */
6 #include <stdio.h> /* remove() snprintf() */
7 7 #include <string.h> /* strcpy() strdup() */ #include <string.h> /* strcpy() strdup() */
8 8
9 9 #include <test-utils.h> #include <test-utils.h>
 
... ... TEST(keepsel_preserves_selection)
478 478 assert_true(lwin.dir_entry[0].selected); assert_true(lwin.dir_entry[0].selected);
479 479 } }
480 480
481 TEST(goto_command)
482 {
483 assert_failure(cmds_dispatch("goto /", &lwin, CIT_COMMAND));
484 assert_failure(cmds_dispatch("goto /no-such-path", &lwin, CIT_COMMAND));
485
486 char cmd[PATH_MAX*2];
487 snprintf(cmd, sizeof(cmd), "goto %s/compare", test_data);
488 assert_success(cmds_dispatch(cmd, &lwin, CIT_COMMAND));
489 assert_true(paths_are_same(lwin.curr_dir, test_data));
490 assert_string_equal("compare", get_current_file_name(&lwin));
491
492 assert_success(cmds_dispatch("goto tree", &lwin, CIT_COMMAND));
493 assert_true(paths_are_same(lwin.curr_dir, test_data));
494 assert_string_equal("tree", get_current_file_name(&lwin));
495 }
496
497 TEST(goto_normalizes_slashes, IF(windows))
498 {
499 char cmd[PATH_MAX*2];
500 snprintf(cmd, sizeof(cmd), "goto %s\\\\compare", test_data);
501 assert_success(cmds_dispatch(cmd, &lwin, CIT_COMMAND));
502 assert_true(paths_are_same(lwin.curr_dir, test_data));
503 assert_string_equal("compare", get_current_file_name(&lwin));
504 }
505
506 481 TEST(echo_reports_all_errors) TEST(echo_reports_all_errors)
507 482 { {
508 483 const char *expected; const char *expected;
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