nitiwiki: add custom tests
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 23 Sep 2014 00:13:02 +0000 (20:13 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Mon, 24 Nov 2014 22:22:10 +0000 (17:22 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

contrib/nitiwiki/tests/Makefile [new file with mode: 0644]
contrib/nitiwiki/tests/nitiwiki.args [new file with mode: 0644]
contrib/nitiwiki/tests/nitiwiki_render.args [new file with mode: 0644]
contrib/nitiwiki/tests/nitiwiki_status.args [new file with mode: 0644]
contrib/nitiwiki/tests/res/nitiwiki.res [new file with mode: 0644]
contrib/nitiwiki/tests/res/nitiwiki_render.res [new file with mode: 0644]
contrib/nitiwiki/tests/res/nitiwiki_status.res [new file with mode: 0644]
contrib/nitiwiki/tests/tests.sh [new file with mode: 0755]

diff --git a/contrib/nitiwiki/tests/Makefile b/contrib/nitiwiki/tests/Makefile
new file mode 100644 (file)
index 0000000..0dce637
--- /dev/null
@@ -0,0 +1,21 @@
+# Copyright 2013 Alexandre Terrasa <alexandre@moz-code.org>.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+all: tests
+
+tests: clean
+       ./tests.sh
+
+clean:
+       rm -rf out/
diff --git a/contrib/nitiwiki/tests/nitiwiki.args b/contrib/nitiwiki/tests/nitiwiki.args
new file mode 100644 (file)
index 0000000..b5abeca
--- /dev/null
@@ -0,0 +1 @@
+nitiwiki
diff --git a/contrib/nitiwiki/tests/nitiwiki_render.args b/contrib/nitiwiki/tests/nitiwiki_render.args
new file mode 100644 (file)
index 0000000..6f7050e
--- /dev/null
@@ -0,0 +1 @@
+nitiwiki --config wiki1/config.ini --clean --render -v
diff --git a/contrib/nitiwiki/tests/nitiwiki_status.args b/contrib/nitiwiki/tests/nitiwiki_status.args
new file mode 100644 (file)
index 0000000..aa96d13
--- /dev/null
@@ -0,0 +1 @@
+nitiwiki --config wiki1/config.ini --clean --status
diff --git a/contrib/nitiwiki/tests/res/nitiwiki.res b/contrib/nitiwiki/tests/res/nitiwiki.res
new file mode 100644 (file)
index 0000000..232b5ef
--- /dev/null
@@ -0,0 +1,2 @@
+Not in a nitiwiki directory.
+Use --init to initialize one here.
diff --git a/contrib/nitiwiki/tests/res/nitiwiki_render.res b/contrib/nitiwiki/tests/res/nitiwiki_render.res
new file mode 100644 (file)
index 0000000..adf25a7
--- /dev/null
@@ -0,0 +1 @@
+Render section out
diff --git a/contrib/nitiwiki/tests/res/nitiwiki_status.res b/contrib/nitiwiki/tests/res/nitiwiki_status.res
new file mode 100644 (file)
index 0000000..936a764
--- /dev/null
@@ -0,0 +1,10 @@
+nitiWiki
+name: wiki1
+config: wiki1/config.ini
+url: http://localhost/
+
+There is modified files:
+ + pages
+ + /pages/index.md
+
+Use nitiwiki --render to render modified files
diff --git a/contrib/nitiwiki/tests/tests.sh b/contrib/nitiwiki/tests/tests.sh
new file mode 100755 (executable)
index 0000000..2acbe94
--- /dev/null
@@ -0,0 +1,92 @@
+#!/bin/bash
+
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2014 Alexandre Terrasa <alexandre@moz-code.org>.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+BIN=../bin
+OUT=./out
+RES=./res
+
+# check args files
+test_args()
+{
+       local test="$1"
+       local args=`cat $test.args`
+       local outdir=$OUT/$test.files
+
+       echo $BIN/$args > $OUT/$test.bin
+       chmod +x $OUT/$test.bin
+       OUTDIR=$outdir $OUT/$test.bin > $OUT/$test.res 2> $OUT/$test.err
+
+       if [ -r $outdir ]; then
+               ls -aR $outdir >> $OUT/$test.res
+       fi
+
+       diff $OUT/$test.res $RES/$test.res > $OUT/$test.diff 2> /dev/null
+}
+
+# return
+#  0 if the sav not exists
+#  1 if the file does match
+#  2 if the file does not match
+check_result() {
+       local test="$1"
+
+       if [ ! -r "$RES/$test.res" ]; then
+               return 0
+       elif [ ! -s $OUT/$test.diff ]; then
+               return 1
+       else
+               return 2
+       fi
+}
+
+echo "Testing..."
+echo ""
+
+rm -rf $OUT 2>/dev/null
+mkdir $OUT 2>/dev/null
+
+all=0
+ok=0
+ko=0
+sk=0
+
+for file in `ls *.args`; do
+       ((all++))
+       test="${file%.*}"
+       echo -n "* $test: "
+
+       test_args $test
+       check_result $test
+
+       case "$?" in
+               0)
+                       echo "skip ($test.res not found)"
+                       ((sk++))
+                       continue;;
+               1)
+                       echo "success"
+                       ((ok++))
+                       ;;
+               2)
+                       echo "error (diff $OUT/$test.res $RES/$test.res)"
+                       ((ko++))
+                       ;;
+       esac
+done
+echo ""
+echo "==> success $ok/$all ($ko tests failed, $sk skipped)"