diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4dbf604 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +t/test-results/ diff --git a/t/Makefile b/t/Makefile new file mode 100644 index 0000000..e10d3e2 --- /dev/null +++ b/t/Makefile @@ -0,0 +1,40 @@ +SHELL_PATH ?= $(SHELL) +PROVE ?= prove +DEFAULT_TEST_TARGET ?= test + +SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) + +T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)) + +all: $(DEFAULT_TEST_TARGET) + +test: pre-clean + @$(MAKE) aggregate-results-and-cleanup + +prove: pre-clean + @echo '*** prove ***'; prove --exec '$(SHELL_PATH_SQ)' $(PROVE_OPTS) $(T) :: $(TEST_OPTS) + @$(MAKE) clean-except-prove-cache + +aggregate-results: + @for f in test-results/t*-*.counts; do \ + echo "$$f"; \ + done | '$(SHELL_PATH_SQ)' ./sharness/aggregate-results.sh + +pre-clean: + @$(RM) -r test-results + +clean-except-prove-cache: + @$(RM) -r 'trash directory'.* test-results + +clean: clean-except-prove-cache + @$(RM) .prove + +aggregate-results-and-cleanup: $(T) + @$(MAKE) aggregate-results + @$(MAKE) clean + +$(T): + @echo '*** $@ ***'; '$(SHELL_PATH_SQ)' $@ + +.PHONY: all test prove aggregate-results $(T) +.PHONY: pre-clean clean-except-prove-cache clean aggregate-results-and-cleanup diff --git a/t/README.md b/t/README.md new file mode 100644 index 0000000..0f93dd3 --- /dev/null +++ b/t/README.md @@ -0,0 +1,33 @@ +# test suite + +This test suite is based on [sharness](http://mlafeldt.github.io/sharness/) + +## install + +It is installed (from toplevel dir) with: + + git subtree add --squash --prefix t/sharness https://github.com/mlafeldt/sharness master + +and update from time to time with: + + git subtree pull --squah --prefix t/sharness master + +Read http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/ for more info on git subtree, you can define a remote to simplify commands or contribute sharness from your fork + +## automation + +Although every test is executable by itselft an only depends on sharness, that's not operative. this test suite relays on [prove](http://search.cpan.org/dist/Test-Harness/bin/prove) and ancient and good-know [make](http://www.gnu.org/software/make/) to complete the test suite. Launch it with + + make + +or + + make DEFAULT_TEST_TARGET=prove + +## Credits + +Makefile was shamelessly stolen from [git-integration](https://github.com/johnkeeping/git-integration/blob/master/t/Makefile) + +Test cases are strongly based on [bash_ini_parser test suite](https://github.com/rudimeier/bash_ini_parser/blob/master/test/test.sh) + + diff --git a/t/t0000-test-setup.sh b/t/t0000-test-setup.sh new file mode 100755 index 0000000..b0c3702 --- /dev/null +++ b/t/t0000-test-setup.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +test_description="Show basic features of Sharness" + +. sharness/sharness.sh + +test_expect_success "Success is reported like this" " + echo hello world | grep hello +" + +test_expect_success "Commands are chained this way" " + test x = 'x' && + test 2 -gt 1 && + echo success +" + +return_42() { + echo "Will return soon" + return 42 +} + +test_expect_success "You can test for a specific exit code" " + test_expect_code 42 return_42 +" + +test_expect_failure SKIP "We expect this to fail" " + test 1 = 2 +" + +test_done diff --git a/t/t0001-parse.sh b/t/t0001-parse.sh new file mode 100755 index 0000000..968dd9f --- /dev/null +++ b/t/t0001-parse.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +SHARNESS_TEST_EXTENSION="sh" + +test_description="check parse" + +. sharness/sharness.sh + +. ../../bash-ini-parser + +DIR_TEST=$SHARNESS_TEST_DIRECTORY/t0001 + +test_expect_success "Whitespace parse" " + cfg_parser $DIR_TEST/test1.ini && + cfg_writer > test1.out && + diff -u test1.out $DIR_TEST/test1.out.correct +" + +test_done diff --git a/t/t0001/test1.ini b/t/t0001/test1.ini new file mode 100644 index 0000000..7734bb8 --- /dev/null +++ b/t/t0001/test1.ini @@ -0,0 +1,17 @@ +;seccion one: clean whitespace +[sec1] + var1 = foo + var2 =hoge + var3 = fuga + var4= pivo +[sec2] +;this is the variable we want +var1=bar +var2=foo +var3=eco +;this is a multiword value +var4="piyo baz qux" +;this is an array +var5=foo bar baz hoge +var6=hoge + diff --git a/t/t0001/test1.out.correct b/t/t0001/test1.out.correct new file mode 100644 index 0000000..6fc3b36 --- /dev/null +++ b/t/t0001/test1.out.correct @@ -0,0 +1,13 @@ +[sec1] +var1="foo" +var2="hoge" +var3="fuga" +var4="pivo" +[sec2] +var1="bar" +var2="foo" +var3="eco" +var4="piyo baz qux" +;var5 is an array +var5="foo bar baz hoge" +var6="hoge"