Skip to content

Commit

Permalink
Add test framework
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonas committed May 20, 2014
1 parent 65a4b54 commit 4295ede
Show file tree
Hide file tree
Showing 65 changed files with 1,579 additions and 15,745 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -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
Expand Down
26 changes: 18 additions & 8 deletions Makefile
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions NEWS.adoc
Expand Up @@ -8,6 +8,7 @@ Improvement:

- Add `:save-display <file>` prompt command to save the current display.
- Add `:script <file>` prompt command for scripting the Tig UI.
- Add test framework and convert existing tests to use it.

tig-2.0.2
---------
Expand Down
12 changes: 8 additions & 4 deletions src/tig.c
Expand Up @@ -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)) {
Expand Down
18 changes: 0 additions & 18 deletions test/builtin-config.sh

This file was deleted.

17 changes: 17 additions & 0 deletions test/test-graph-samples/simple.in → test/graph/00-simple-test 100644 → 100755
@@ -1,3 +1,10 @@
#!/bin/sh
#
# Graph test: simple

. libtest.sh

test_graph <<EOF
commit f e d
Merge branch 'branch3'
commit e b c
Expand All @@ -20,3 +27,13 @@ commit a
* | e51b810 (branch1) branch1
|/
* de1bd54 init
EOF

assert_equals stdout <<EOF
●─╮ Merge branch 'branch3'
●─│─╮ Merge branch 'branch2'
│ ● │ branch3
│ │ ● branch2
● │ │ branch1
◎─┴─╯ init
EOF
26 changes: 26 additions & 0 deletions test/graph/01-merge-from-left-test
@@ -0,0 +1,26 @@
#!/bin/sh
#
# Graph test: merge from left

. libtest.sh

test_graph <<EOF
commit A B C
Commit A - Merge C into B
commit C B D
Commit C - Merge D into B
commit B E
Commit B after E
commit E D
Commit E after D
commit D
Commit D
EOF

assert_equals stdout <<EOF
●─╮ Commit A - Merge C into B
│ ●─╮ Commit C - Merge D into B
●─╯ │ Commit B after E
● ╭─╯ Commit E after D
◎─╯ Commit D
EOF
38 changes: 38 additions & 0 deletions test/graph/02-duplicate-parent-test
@@ -0,0 +1,38 @@
#!/bin/sh
#
# Graph test: duplicate parent

. libtest.sh

test_graph <<EOF
commit A B C
Commit A - Merge C into B
commit B C E
Commit B - Merge E into C
commit C D
Commit C after D
commit E D
Commit E after D
commit D F
Commit D after F
commit F G H
Commit F - Merge H into G
commit G H I
Commit G - Merge I into H
commit I H
Commit I after H
commit H
Commit H
EOF

assert_equals stdout <<EOF
●─╮ Commit A - Merge C into B
●─│─╮ Commit B - Merge E into C
●─╯ │ Commit C after D
│ ●─╯ Commit E after D
●─╯ Commit D after F
●─╮ Commit F - Merge H into G
●─│─╮ Commit G - Merge I into H
│ │ ● Commit I after H
◎─┴─╯ Commit H
EOF
26 changes: 26 additions & 0 deletions test/graph/03-octo-merge-test
@@ -0,0 +1,26 @@
#!/bin/sh
#
# Graph test: octo merge

. libtest.sh

test_graph <<EOF
commit A B C D
Commit A - Merges B, C, and D
commit C E
Commit C after E
commit E D B
Commit E - Merges D and B
commit B D
Commit B after D
commit D
Commit D
EOF

assert_equals stdout <<EOF
●─┬─╮ Commit A - Merges B, C, and D
│ ● │ Commit C after E
│ ●─│─╮ Commit E - Merges D and B
●─│─│─╯ Commit B after D
◎─┴─╯ Commit D
EOF
32 changes: 32 additions & 0 deletions test/graph/04-missing-bar-test
@@ -0,0 +1,32 @@
#!/bin/sh
#
# Graph test: missing bar

. libtest.sh

test_graph <<EOF
commit A B C
Commit A - Merge B and C
commit B D E
Commit B - Merge D and E
commit C F
Commit C after F
commit F G D
Commit F - Merge G and D
commit D G
Commit D after G
commit G E
Commit G after E
commit E
Commit E
EOF

assert_equals stdout <<EOF
●─╮ Commit A - Merge B and C
●─│─╮ Commit B - Merge D and E
│ ● │ Commit C after F
│ ●─│─╮ Commit F - Merge G and D
●─│─│─╯ Commit D after G
●─╯ │ Commit G after E
◎───╯ Commit E
EOF
29 changes: 29 additions & 0 deletions test/graph/05-extra-pipe-test
@@ -0,0 +1,29 @@
#!/bin/sh
#
# Graph test: extra pipe

. libtest.sh

test_graph <<EOF
commit A B C
Commit A - merge B and C
commit C D
Commit C after D
commit B E D
Commit B - merge E and D
commit D F
Commit D after F
commit E
Commit E
commit F
Commit F
EOF

assert_equals stdout <<EOF
●─╮ Commit A - merge B and C
│ ● Commit C after D
●─│─╮ Commit B - merge E and D
│ ●─╯ Commit D after F
◎ │ Commit E
◎─╯ Commit F
EOF

0 comments on commit 4295ede

Please sign in to comment.