From 1085b8b5e351f0c62e30d3da9c06ebb3b628d54b Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Tue, 6 May 2014 21:32:58 -0400 Subject: [PATCH 01/96] Move cursor to the first line when :0 is entered This aliases `:0` to `:1`. --- src/prompt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/prompt.c b/src/prompt.c index 22af8da9b..1981fe792 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -755,7 +755,9 @@ run_prompt_command(struct view *view, const char *argv[]) if (string_isnumber(cmd)) { int lineno = view->pos.lineno + 1; - if (parse_int(&lineno, cmd, 1, view->lines + 1) == SUCCESS) { + if (parse_int(&lineno, cmd, 0, view->lines + 1) == SUCCESS) { + if (!lineno) + lineno = 1; select_view_line(view, lineno - 1); report_clear(); } else { From 7724e4e1f2ec5827b7bc1266f8e068410c3b8a24 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Thu, 8 May 2014 20:17:08 -0400 Subject: [PATCH 02/96] Fix documentation of author width option Auto-abbreviation is enabled when the width is in the rante 1..10. --- doc/tigrc.5.adoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc index ae498b878..7473d38fd 100644 --- a/doc/tigrc.5.adoc +++ b/doc/tigrc.5.adoc @@ -335,9 +335,9 @@ author:: - 'display' (mixed) [full|abbreviated|email|email-user|]: How to display author names. If set to "abbreviated" author initials will be shown. - - 'width' (int): Width of the column. When set to 5 or below, the author - name will be abbreviated to the author's initials. When set to zero, - the width is automatically sized to fit the content. + - 'width' (int): Width of the column. When set to a value between 1 and + 10, the author name will be abbreviated to the author's initials. + When set to zero, the width is automatically sized to fit the content. commit-title:: - 'graph' (bool): Whether to show revision graph in the main view on From 3cfa9ad96a7e3a1b07737cf8290cea60d120313c Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Thu, 8 May 2014 21:50:53 -0400 Subject: [PATCH 03/96] Fix release script to work for patch versions --- tools/release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/release.sh b/tools/release.sh index 85f782c35..a260684fc 100755 --- a/tools/release.sh +++ b/tools/release.sh @@ -34,7 +34,7 @@ if test -n "$VERSION"; then git checkout master # Update files which should reference the version. - sed -i "s/VERSION\s=\s[0-9]\+[.][0-9]\+/VERSION = $VERSION/" Makefile + sed -i "s/VERSION\s=\s[0-9]\+\([.][0-9]\+\)\+/VERSION = $VERSION/" Makefile perl -pi -e 's/^tig master.*/@@TITLE@@/ms' "$NEWS" perl -pi -e "s/^@@TITLE@@.*/$TITLE/" "$NEWS" From c43e75547f944ec3b6895c89be18b4d11020b990 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Thu, 8 May 2014 22:01:09 -0400 Subject: [PATCH 04/96] tig-2.0.2 --- Makefile | 2 +- NEWS.adoc | 11 +++++++++-- tools/aspell.dict | 12 ++++++------ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 6d684b7b4..3c7d96c09 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # The last tagged version. Can be overridden either by the version from # git or from the value of the DIST_VERSION environment variable. -VERSION = 2.0.1 +VERSION = 2.0.2.1 all: diff --git a/NEWS.adoc b/NEWS.adoc index 82d9d9be0..cb6d56c56 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -1,14 +1,21 @@ Release notes ============= -master ------- +tig-2.0.2 +--------- + +Improvements: + + - Use git-status for diffing the index. + - Group toggle options together in the help view. Bug fixes: - Fix refs, main and grep loading when 'gui.encoding' is set. (GH #287) - Ignore 'gui.encoding' and 'i18n.commitencoding' when set to 'UTF-8'. - Add work-around for missing strndup() on Mac OS X v10.6. (GH #286) + - Fix spurious abbreviation of author names. (GH #288) + - Don't show empty action groups in the help view. tig-2.0.1 --------- diff --git a/tools/aspell.dict b/tools/aspell.dict index ad67a3146..6f752139c 100644 --- a/tools/aspell.dict +++ b/tools/aspell.dict @@ -23,7 +23,6 @@ args asciidoc AsciiDoc unstanged -gitattributes revgraph revargs topo @@ -81,6 +80,7 @@ README submodules Reenable xhtml +gitattributes aterm mkstemps iconv @@ -89,17 +89,16 @@ Scrool ELinks subdir Debian -subdirectories gui bindir tigmanual -reachability PgUp wrt libiconv unicode multi Na๏vely +reachability autoconf xpm filesystem @@ -114,7 +113,6 @@ tigblob autobuild reflog diffargs -commitencoding erasechar lds bg @@ -150,11 +148,12 @@ Git's tig's dirs ld -subdirectory newmode keymaps endif namespace +commitencoding +subdirectory utils delim unstaged @@ -165,6 +164,7 @@ VLINE extdiff keybindings ifndef +subdirectories multibyte COLORTERM ncursesw @@ -201,11 +201,11 @@ Yy fgcolor localtime filename -backgrounded lncursesw waitpid wgetch Pre +backgrounded waddch subcommand errno From a6745fea36d7fa7116710ce1c941eeb313b5b245 Mon Sep 17 00:00:00 2001 From: Vivien Didelot Date: Wed, 14 May 2014 07:42:00 -0400 Subject: [PATCH 05/96] argv: ensure closing parenthesis in variables While format_expand_arg() can assume a variable is well formed, format_append_arg() should not. A command using '%(prompt' without closing parenthesis causes Tig to segfault. This is due to format_append_arg() which assumes the presence of a ')' char, resulting in the 'next' variable being 0x1 (NULL + 1). This patch checks for this case and return FALSE in consequence. In the meantime, constify variables in these two functions. Signed-off-by: Vivien Didelot --- src/argv.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/argv.c b/src/argv.c index b5bf5bb72..29f3a5feb 100644 --- a/src/argv.c +++ b/src/argv.c @@ -228,7 +228,7 @@ format_expand_arg(struct format_context *format, const char *name, const char *e char msgbuf[SIZEOF_STR]; const char *value; const char *msgstart = name + STRING_SIZE("%(prompt"); - int msglen = end - msgstart - 1; + const int msglen = end - msgstart - 1; if (end && msglen > 0 && string_format(msgbuf, "%.*s", msglen, msgstart)) { const char *msg = msgbuf; @@ -271,9 +271,13 @@ format_append_arg(struct format_context *format, const char ***dst_argv, const c format->bufpos = 0; while (arg) { - char *var = strstr(arg, "%("); - int len = var ? var - arg : strlen(arg); - char *next = var ? strchr(var, ')') + 1 : NULL; + const char *var = strstr(arg, "%("); + const char *closing = var ? strchr(var, ')') : NULL; + const char *next = closing ? closing + 1 : NULL; + const int len = var ? var - arg : strlen(arg); + + if (var && !closing) + return FALSE; if (len && !string_format_from(format->buf, &format->bufpos, "%.*s", len, arg)) return FALSE; From 3a8df04e62c9177417ca13e898ab54df5b1ce4fe Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Thu, 15 May 2014 00:02:30 -0400 Subject: [PATCH 06/96] Move enum input_status to prompt header --- include/tig/display.h | 8 -------- include/tig/prompt.h | 8 ++++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/tig/display.h b/include/tig/display.h index a9586cf4f..91de1a054 100644 --- a/include/tig/display.h +++ b/include/tig/display.h @@ -17,14 +17,6 @@ #include "tig/tig.h" #include "tig/keys.h" -enum input_status { - INPUT_OK, - INPUT_SKIP, - INPUT_DELETE, - INPUT_STOP, - INPUT_CANCEL -}; - int get_input(int prompt_position, struct key *key, bool modifiers); extern WINDOW *status_win; diff --git a/include/tig/prompt.h b/include/tig/prompt.h index 333aefc15..9e61b3049 100644 --- a/include/tig/prompt.h +++ b/include/tig/prompt.h @@ -20,6 +20,14 @@ struct view; struct input; +enum input_status { + INPUT_OK, + INPUT_SKIP, + INPUT_DELETE, + INPUT_STOP, + INPUT_CANCEL +}; + struct menu_item { int hotkey; const char *text; From 343844b52ddc2f629c058a541320018275affc89 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Thu, 15 May 2014 00:31:23 -0400 Subject: [PATCH 07/96] Add :save-display command This allows to dump the current ncurses screen data to a file. The main use is for testing. The command optionally takes a file name. --- NEWS.adoc | 7 +++++ include/tig/display.h | 1 + src/display.c | 64 +++++++++++++++++++++++++++++++++++++++++++ src/prompt.c | 9 ++++++ 4 files changed, 81 insertions(+) diff --git a/NEWS.adoc b/NEWS.adoc index cb6d56c56..0c377cb08 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -1,6 +1,13 @@ Release notes ============= +master +------ + +Improvement: + + - Add `:save-display ` prompt command to save the current display. + tig-2.0.2 --------- diff --git a/include/tig/display.h b/include/tig/display.h index 91de1a054..4b7b73dd5 100644 --- a/include/tig/display.h +++ b/include/tig/display.h @@ -45,6 +45,7 @@ extern unsigned int current_view; void init_display(void); void resize_display(void); void redraw_display(bool clear); +bool save_display(const char *path); bool open_external_viewer(const char *argv[], const char *dir, bool confirm, bool refresh, const char *notice); void open_editor(const char *file, unsigned int lineno); diff --git a/src/display.c b/src/display.c index df04b87df..c941a6bda 100644 --- a/src/display.c +++ b/src/display.c @@ -243,6 +243,70 @@ redraw_display(bool clear) redraw_display_separator(clear); } +static bool +save_window_line(FILE *file, WINDOW *win, int y, char *buf, size_t bufsize) +{ + int read = mvwinnstr(win, y, 0, buf, bufsize); + + return read == ERR ? FALSE : fprintf(file, "%s\n", buf) == read + 1; +} + +static bool +save_window_vline(FILE *file, WINDOW *left, WINDOW *right, int y, char *buf, size_t bufsize) +{ + int read1 = mvwinnstr(left, y, 0, buf, bufsize); + int read2 = read1 == ERR ? ERR : mvwinnstr(right, y, 0, buf + read1 + 1, bufsize - read1 - 1); + + if (read2 == ERR) + return FALSE; + buf[read1] = '|'; + + return fprintf(file, "%s\n", buf) == read1 + 1 + read2 + 1; +} + +bool +save_display(const char *path) +{ + int i, width; + char *line; + FILE *file = fopen(path, "w"); + bool ok = TRUE; + struct view *view = display[0]; + + if (!file) + return FALSE; + + getmaxyx(stdscr, i, width); + line = malloc(width + 1); + if (!line) { + fclose(file); + return FALSE; + } + + if (view->width < width) { + struct view *left = display[0], + *right = display[1]; + + for (i = 0; ok && i < left->height; i++) + ok = save_window_vline(file, left->win, right->win, i, line, width); + if (ok) + ok = save_window_vline(file, left->title, right->title, 0, line, width); + } else { + int j; + + foreach_displayed_view (view, j) { + for (i = 0; ok && i < view->height; i++) + ok = save_window_line(file, view->win, i, line, width); + if (ok) + ok = save_window_line(file, view->title, 0, line, width); + } + } + + free(line); + fclose(file); + return ok; +} + /* * Status management */ diff --git a/src/prompt.c b/src/prompt.c index 1981fe792..c8ade3229 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -233,6 +233,7 @@ readline_action_generator(const char *text, int state) "bind", "set", "toggle", + "save-display", #define REQ_GROUP(help) #define REQ_(req, help) #req REQ_INFO, @@ -823,6 +824,14 @@ run_prompt_command(struct view *view, const char *argv[]) open_pager_view(view, OPEN_PREPARED | OPEN_WITH_STDERR); } + } else if (!strcmp(cmd, "save-display")) { + const char *path = argv[1] ? argv[1] : "tig-display.txt"; + + if (!save_display(path)) + report("Failed to save screen to %s", path); + else + report("Saved screen to %s", path); + } else if (!strcmp(cmd, "toggle")) { enum view_flag flags = VIEW_NO_FLAGS; enum status_code code = prompt_toggle(view, argv, &flags); From 66280836ecfaea47c6786b1286e828e1fdce8978 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Thu, 15 May 2014 00:05:47 -0400 Subject: [PATCH 08/96] Add support for running scripts using :script --- NEWS.adoc | 1 + include/tig/display.h | 3 +++ src/display.c | 61 ++++++++++++++++++++++++++++++++++++++++--- src/prompt.c | 10 +++++++ 4 files changed, 71 insertions(+), 4 deletions(-) diff --git a/NEWS.adoc b/NEWS.adoc index 0c377cb08..f06b77443 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -7,6 +7,7 @@ master Improvement: - Add `:save-display ` prompt command to save the current display. + - Add `:script ` prompt command for scripting the Tig UI. tig-2.0.2 --------- diff --git a/include/tig/display.h b/include/tig/display.h index 4b7b73dd5..2ba25a91a 100644 --- a/include/tig/display.h +++ b/include/tig/display.h @@ -51,5 +51,8 @@ bool open_external_viewer(const char *argv[], const char *dir, bool confirm, boo void open_editor(const char *file, unsigned int lineno); void enable_mouse(bool enable); +bool open_script(const char *path); +bool is_script_executing(void); + #endif /* vim: set ts=8 sw=8 noexpandtab: */ diff --git a/src/display.c b/src/display.c index c941a6bda..b09ca8cdd 100644 --- a/src/display.c +++ b/src/display.c @@ -460,6 +460,52 @@ init_display(void) } } +static struct io script_io = { -1 }; + +bool +open_script(const char *path) +{ + return io_open(&script_io, "%s", path); +} + +bool +is_script_executing(void) +{ + return script_io.pipe != -1; +} + +static bool +read_script(struct key *key, int delay) +{ + static struct buffer input_buffer; + static const char *line = ""; + enum status_code code; + + if (!line || !*line) { + if (input_buffer.data && *input_buffer.data == ':') { + line = ""; + memset(&input_buffer, 0, sizeof(input_buffer)); + + } else if (!io_get(&script_io, &input_buffer, '\n', TRUE)) { + io_done(&script_io); + return FALSE; + } else { + line = input_buffer.data; + } + } + + if (!strcmp(line, ":wait")) { + if (delay != 0) + line = input_buffer.data = NULL; + return FALSE; + } + + code = get_key_value(&line, key); + if (code != SUCCESS) + die("Error reading script: %s", get_status_message(code)); + return TRUE; +} + int get_input(int prompt_position, struct key *key, bool modifiers) { @@ -505,10 +551,17 @@ get_input(int prompt_position, struct key *key, bool modifiers) } setsyx(cursor_y, cursor_x); - /* Refresh, accept single keystroke of input */ - doupdate(); - wtimeout(status_win, delay); - key_value = wgetch(status_win); + if (is_script_executing()) { + if (!read_script(key, delay)) + continue; + return key->modifiers.multibytes ? OK : key->data.value; + + } else { + /* Refresh, accept single keystroke of input */ + doupdate(); + wtimeout(status_win, delay); + key_value = wgetch(status_win); + } /* wgetch() with nodelay() enabled returns ERR when * there's no input. */ diff --git a/src/prompt.c b/src/prompt.c index c8ade3229..e96deb3cc 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -444,6 +444,9 @@ read_prompt(const char *prompt) { static char *line = NULL; + if (is_script_executing()) + return read_prompt_incremental(prompt, TRUE, NULL, NULL); + if (line) { free(line); line = NULL; @@ -858,6 +861,13 @@ run_prompt_command(struct view *view, const char *argv[]) if (*action) report("%s", action); + } else if (!strcmp(cmd, "script")) { + if (is_script_executing()) { + report("Scripts cannot be run from scripts"); + } else if (!open_script(argv[1])) { + report("Failed to open %s", argv[1]); + } + } else { struct key key = {}; From 65a4b545053db1c463b1ff5c6c669617ad1b0bdd Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Thu, 15 May 2014 00:28:00 -0400 Subject: [PATCH 09/96] Add TIG_SCRIPT and TIG_NO_DISPLAY environment variables The former allows to execute prompt scripts automatically on startup and the latter forces Tig to not render anything to the terminal. --- doc/tig.1.adoc | 10 ++++++++++ src/display.c | 10 +++++++--- src/tig.c | 9 ++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/doc/tig.1.adoc b/doc/tig.1.adoc index e09661191..ff8c65409 100644 --- a/doc/tig.1.adoc +++ b/doc/tig.1.adoc @@ -201,6 +201,16 @@ TIG_DIFF_OPTS:: TIG_TRACE:: Path for trace file where information about Git commands are logged. +TIG_SCRIPT:: + Path to script that should be executed automatically on startup. If this + environment variable is defined to the empty string, the script is read + from stdin. The script is interpreted line-by-line and can contain + prompt commands and key mappings. + +TIG_NO_DISPLAY:: + Open Tig without rendering anything to the terminal. This force Ncurses + to write to /dev/null. The main use is for automated testing of Tig. + FILES ----- '~/.tigrc':: diff --git a/src/display.c b/src/display.c index b09ca8cdd..ec854c5a8 100644 --- a/src/display.c +++ b/src/display.c @@ -391,6 +391,7 @@ done_display(void) void init_display(void) { + bool no_display = !!getenv("TIG_NO_DISPLAY"); const char *term; int x, y; @@ -400,15 +401,18 @@ init_display(void) die("Failed to register done_display"); /* Initialize the curses library */ - if (isatty(STDIN_FILENO)) { + if (!no_display && isatty(STDIN_FILENO)) { cursed = !!initscr(); opt_tty = stdin; } else { /* Leave stdin and stdout alone when acting as a pager. */ + FILE *out_tty; + opt_tty = fopen("/dev/tty", "r+"); - if (!opt_tty) + out_tty = no_display ? fopen("/dev/null", "w+") : opt_tty; + if (!opt_tty || !out_tty) die("Failed to open /dev/tty"); - cursed = !!newterm(NULL, opt_tty, opt_tty); + cursed = !!newterm(NULL, out_tty, opt_tty); } if (!cursed) diff --git a/src/tig.c b/src/tig.c index d003900db..5423610fd 100644 --- a/src/tig.c +++ b/src/tig.c @@ -679,8 +679,15 @@ main(int argc, const char *argv[]) init_display(); - if (pager_mode) + if (getenv("TIG_SCRIPT")) { + const char *script_command[] = { "script", getenv("TIG_SCRIPT"), NULL }; + + /* Open a 'neutral' view. */ + open_help_view(NULL, OPEN_DEFAULT); + request = run_prompt_command(NULL, script_command); + } else if (pager_mode) { request = open_pager_mode(request); + } while (view_driver(display[current_view], request)) { struct key key; From 4295eded02bb108d5ecbce8d646e3efb145cd88c Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Thu, 15 May 2014 00:00:01 -0400 Subject: [PATCH 10/96] Add test framework This adds a small test framework and updates all existing tests to use it. Tests are now implemented using shell scripts and integration with the build output is much improved. --- .gitignore | 3 +- Makefile | 26 +- NEWS.adoc | 1 + src/tig.c | 12 +- test/builtin-config.sh | 18 - .../simple.in => graph/00-simple-test} | 17 + test/graph/01-merge-from-left-test | 26 + test/graph/02-duplicate-parent-test | 38 + test/graph/03-octo-merge-test | 26 + test/graph/04-missing-bar-test | 32 + test/graph/05-extra-pipe-test | 29 + .../06-extra-bars-test} | 125 + test/graph/07-multi-collapse-test | 35 + test/graph/08-multi-collapse-2-test | 38 + test/graph/09-parallel-siblings-test | 38 + test/graph/10-shorter-merge-than-branch-test | 44 + test/graph/11-new-branch-in-middle-test | 38 + test/graph/12-cross-over-collapse-test | 38 + ...branches-with-different-middle-branch-test | 41 + .../14-long-collapse-line-test} | 51 + .../15-many-merges-test} | 31 + .../16_changes.in => graph/16-changes-test} | 15 + .../more.out => graph/17-more-merges-test} | 83 + .../tig.in => graph/18-tig-test} | 19 + .../tig-all.in => graph/19-tig-all-test} | 47 +- .../20-tig-all-long-test} | 604 +- test/graph/20-tig-all-long-test.in | Bin 0 -> 262208 bytes .../10_shorter_merge_than_branch.in | 22 - .../10_shorter_merge_than_branch.out | 11 - .../11_new_branch_in_middle.in | 18 - .../11_new_branch_in_middle.out | 9 - .../12_cross_over_collapse.in | 18 - .../12_cross_over_collapse.out | 9 - ...l_branches_with_different_middle_branch.in | 20 - ..._branches_with_different_middle_branch.out | 10 - .../14_long_collapse_line.in | 40 - test/test-graph-samples/16_changes.out | 4 - test/test-graph-samples/1_merge_from_left.in | 10 - test/test-graph-samples/1_merge_from_left.out | 5 - test/test-graph-samples/2_duplicate_parent.in | 18 - .../test-graph-samples/2_duplicate_parent.out | 9 - test/test-graph-samples/3_octo_merge.in | 10 - test/test-graph-samples/3_octo_merge.out | 5 - test/test-graph-samples/4_missing_bar.in | 14 - test/test-graph-samples/4_missing_bar.out | 7 - test/test-graph-samples/5_extra_pipe.in | 12 - test/test-graph-samples/5_extra_pipe.out | 6 - test/test-graph-samples/6_extra_bars.in | 115 - test/test-graph-samples/7_multi_collapse.in | 16 - test/test-graph-samples/7_multi_collapse.out | 8 - test/test-graph-samples/8_multi_collapse_2.in | 18 - .../test-graph-samples/8_multi_collapse_2.out | 9 - .../test-graph-samples/9_parallel_siblings.in | 18 - .../9_parallel_siblings.out | 9 - test/test-graph-samples/many_merges.out | 20 - test/test-graph-samples/more.in | 72 - test/test-graph-samples/simple.out | 6 - test/test-graph-samples/tig-all-long.in | 14986 ---------------- test/test-graph-samples/tig-all.out | 35 - test/test-graph-samples/tig.out | 8 - test/tigrc/builtin-error-test | 12 + test/tools/libtest.sh | 175 + test/tools/show-results.sh | 30 + test/{ => tools}/test-graph.c | 36 +- test/unit-test-graph.sh | 19 - 65 files changed, 1579 insertions(+), 15745 deletions(-) delete mode 100755 test/builtin-config.sh rename test/{test-graph-samples/simple.in => graph/00-simple-test} (72%) mode change 100644 => 100755 create mode 100755 test/graph/01-merge-from-left-test create mode 100755 test/graph/02-duplicate-parent-test create mode 100755 test/graph/03-octo-merge-test create mode 100755 test/graph/04-missing-bar-test create mode 100755 test/graph/05-extra-pipe-test rename test/{test-graph-samples/6_extra_bars.out => graph/06-extra-bars-test} (51%) mode change 100644 => 100755 create mode 100755 test/graph/07-multi-collapse-test create mode 100755 test/graph/08-multi-collapse-2-test create mode 100755 test/graph/09-parallel-siblings-test create mode 100755 test/graph/10-shorter-merge-than-branch-test create mode 100755 test/graph/11-new-branch-in-middle-test create mode 100755 test/graph/12-cross-over-collapse-test create mode 100755 test/graph/13-collapse-parallel-branches-with-different-middle-branch-test rename test/{test-graph-samples/14_long_collapse_line.out => graph/14-long-collapse-line-test} (52%) mode change 100644 => 100755 rename test/{test-graph-samples/many_merges.in => graph/15-many-merges-test} (74%) mode change 100644 => 100755 rename test/{test-graph-samples/16_changes.in => graph/16-changes-test} (68%) mode change 100644 => 100755 rename test/{test-graph-samples/more.out => graph/17-more-merges-test} (57%) mode change 100644 => 100755 rename test/{test-graph-samples/tig.in => graph/18-tig-test} (68%) mode change 100644 => 100755 rename test/{test-graph-samples/tig-all.in => graph/19-tig-all-test} (87%) mode change 100644 => 100755 rename test/{test-graph-samples/tig-all-long.out => graph/20-tig-all-long-test} (74%) mode change 100644 => 100755 create mode 100644 test/graph/20-tig-all-long-test.in delete mode 100644 test/test-graph-samples/10_shorter_merge_than_branch.in delete mode 100644 test/test-graph-samples/10_shorter_merge_than_branch.out delete mode 100644 test/test-graph-samples/11_new_branch_in_middle.in delete mode 100644 test/test-graph-samples/11_new_branch_in_middle.out delete mode 100644 test/test-graph-samples/12_cross_over_collapse.in delete mode 100644 test/test-graph-samples/12_cross_over_collapse.out delete mode 100644 test/test-graph-samples/13_collapse_parallel_branches_with_different_middle_branch.in delete mode 100644 test/test-graph-samples/13_collapse_parallel_branches_with_different_middle_branch.out delete mode 100644 test/test-graph-samples/14_long_collapse_line.in delete mode 100644 test/test-graph-samples/16_changes.out delete mode 100644 test/test-graph-samples/1_merge_from_left.in delete mode 100644 test/test-graph-samples/1_merge_from_left.out delete mode 100644 test/test-graph-samples/2_duplicate_parent.in delete mode 100644 test/test-graph-samples/2_duplicate_parent.out delete mode 100644 test/test-graph-samples/3_octo_merge.in delete mode 100644 test/test-graph-samples/3_octo_merge.out delete mode 100644 test/test-graph-samples/4_missing_bar.in delete mode 100644 test/test-graph-samples/4_missing_bar.out delete mode 100644 test/test-graph-samples/5_extra_pipe.in delete mode 100644 test/test-graph-samples/5_extra_pipe.out delete mode 100644 test/test-graph-samples/6_extra_bars.in delete mode 100644 test/test-graph-samples/7_multi_collapse.in delete mode 100644 test/test-graph-samples/7_multi_collapse.out delete mode 100644 test/test-graph-samples/8_multi_collapse_2.in delete mode 100644 test/test-graph-samples/8_multi_collapse_2.out delete mode 100644 test/test-graph-samples/9_parallel_siblings.in delete mode 100644 test/test-graph-samples/9_parallel_siblings.out delete mode 100644 test/test-graph-samples/many_merges.out delete mode 100644 test/test-graph-samples/more.in delete mode 100644 test/test-graph-samples/simple.out delete mode 100644 test/test-graph-samples/tig-all-long.in delete mode 100644 test/test-graph-samples/tig-all.out delete mode 100644 test/test-graph-samples/tig.out create mode 100755 test/tigrc/builtin-error-test create mode 100644 test/tools/libtest.sh create mode 100755 test/tools/show-results.sh rename test/{ => tools}/test-graph.c (78%) delete mode 100755 test/unit-test-graph.sh diff --git a/.gitignore b/.gitignore index 4e6a72782..09d71b878 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,8 @@ doc/release-docs/ src/builtin-config.c src/tig tags -test/test-graph +test/tools/test-graph +test/tmp tig-*.tar.gz tig-*.tar.gz.md5 tig.spec diff --git a/Makefile b/Makefile index 3c7d96c09..a54446a30 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ LDLIBS ?= -lcurses CFLAGS ?= -Wall -O2 DFLAGS = -g -DDEBUG -Werror -O0 EXE = src/tig -TOOLS = test/test-graph tools/doc-gen +TOOLS = test/tools/test-graph tools/doc-gen TXTDOC = doc/tig.1.adoc doc/tigrc.5.adoc doc/manual.adoc NEWS.adoc README.adoc INSTALL.adoc MANDOC = doc/tig.1 doc/tigrc.5 doc/tigmanual.7 HTMLDOC = doc/tig.1.html doc/tigrc.5.html doc/manual.html README.html INSTALL.html NEWS.html @@ -103,7 +103,7 @@ install-release-doc-html: install-doc: install-doc-man install-doc-html install-release-doc: install-release-doc-man install-release-doc-html -clean: +clean: clean-test $(RM) -r $(TARNAME) *.spec tig-*.tar.gz tig-*.tar.gz.md5 .deps $(RM) $(EXE) $(TOOLS) $(OBJS) core doc/*.xml src/builtin-config.c @@ -153,16 +153,24 @@ dist: configure tig.spec rpm: dist rpmbuild -ta $(TARNAME).tar.gz -test: $(TOOLS) - test/unit-test-graph.sh - test/builtin-config.sh +TESTS = $(sort $(shell find test -type f -name '*-test')) + +clean-test: + $(Q)$(RM) -r test/tmp + +test: clean-test $(TESTS) + $(QUIET_SUMMARY)test/tools/show-results.sh + +$(TESTS): PATH := $(CURDIR)/test/tools:$(CURDIR)/src:$(PATH) +$(TESTS): $(EXE) test/tools/test-graph + $(QUIET_TEST)$@ # Other autoconf-related rules are hidden in config.make.in so that # they don't confuse Make when we aren't actually using ./configure configure: configure.ac acinclude.m4 tools/*.m4 ./autogen.sh -.PHONY: all all-debug doc doc-man doc-html install install-doc \ +.PHONY: all all-debug doc doc-man doc-html install install-doc $(TESTS) \ install-doc-man install-doc-html clean spell-check dist rpm test ifdef NO_MKSTEMPS @@ -222,8 +230,8 @@ TIG_OBJS = \ src/tig: $(TIG_OBJS) -TEST_GRAPH_OBJS = test/test-graph.o src/string.o src/util.o src/io.o src/graph.o $(COMPAT_OBJS) -test/test-graph: $(TEST_GRAPH_OBJS) +TEST_GRAPH_OBJS = test/tools/test-graph.o src/string.o src/util.o src/io.o src/graph.o $(COMPAT_OBJS) +test/tools/test-graph: $(TEST_GRAPH_OBJS) DOC_GEN_OBJS = tools/doc-gen.o src/string.o src/types.o src/util.o src/request.o tools/doc-gen: $(DOC_GEN_OBJS) @@ -317,6 +325,8 @@ QUIET_DB2PDF = $(Q:@=@echo ' DB2PDF '$@;) # tools/install.sh will print 'file -> $install_dir/file' QUIET_INSTALL = $(Q:@=@printf ' INSTALL ';) QUIET_INSTALL_EACH = $(Q:@=printf ' INSTALL ';) +QUIET_TEST = $(Q:@=@printf ' TEST '$@;) +QUIET_SUMMARY = $(Q:@=@printf ' SUMMARY ';) export V endif diff --git a/NEWS.adoc b/NEWS.adoc index f06b77443..78c5e6eb7 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -8,6 +8,7 @@ Improvement: - Add `:save-display ` prompt command to save the current display. - Add `:script ` prompt command for scripting the Tig UI. + - Add test framework and convert existing tests to use it. tig-2.0.2 --------- diff --git a/src/tig.c b/src/tig.c index 5423610fd..00f2aaf14 100644 --- a/src/tig.c +++ b/src/tig.c @@ -679,14 +679,18 @@ main(int argc, const char *argv[]) init_display(); + if (pager_mode) + request = open_pager_mode(request); + if (getenv("TIG_SCRIPT")) { const char *script_command[] = { "script", getenv("TIG_SCRIPT"), NULL }; - /* Open a 'neutral' view. */ - open_help_view(NULL, OPEN_DEFAULT); + if (!displayed_views()) { + /* Open a 'neutral' view. */ + open_help_view(NULL, OPEN_DEFAULT); + } + request = run_prompt_command(NULL, script_command); - } else if (pager_mode) { - request = open_pager_mode(request); } while (view_driver(display[current_view], request)) { diff --git a/test/builtin-config.sh b/test/builtin-config.sh deleted file mode 100755 index f3ad16dcb..000000000 --- a/test/builtin-config.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -result=0 - -export GIT_DIR=./does-not-exist -export TIGRC_SYSTEM= -export TIGRC_USER= - -src/tig 2>&1 | grep -q "tig: Error in built-in config" -if [ $? == 0 ] -then - echo "not ok - Errors reported in built-in config" - result=$(($result+1)) -else - echo "ok - Built-in config loaded" -fi - -exit $result diff --git a/test/test-graph-samples/simple.in b/test/graph/00-simple-test old mode 100644 new mode 100755 similarity index 72% rename from test/test-graph-samples/simple.in rename to test/graph/00-simple-test index 8e84e03e9..de462929f --- a/test/test-graph-samples/simple.in +++ b/test/graph/00-simple-test @@ -1,3 +1,10 @@ +#!/bin/sh +# +# Graph test: simple + +. libtest.sh + +test_graph < 1381189194 -0400 committer Jonas Fonseca 1381189194 -0400 Fix and improve inter-document linking - +EOF + +assert_equals stdout <