aboutsummaryrefslogtreecommitdiffstats
path: root/tests/blogc-git-receiver
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-10-07 01:48:16 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-10-07 01:48:16 +0200
commit2c1b2eaaef8726c71648b4a115fbe628f28d6b4b (patch)
tree3d34829130ee8870e268d3fcd19d4149e66b1be6 /tests/blogc-git-receiver
parent13be5bd50238daa2be6b42104ba20aeea427655b (diff)
downloadblogc-2c1b2eaaef8726c71648b4a115fbe628f28d6b4b.tar.gz
blogc-2c1b2eaaef8726c71648b4a115fbe628f28d6b4b.tar.bz2
blogc-2c1b2eaaef8726c71648b4a115fbe628f28d6b4b.zip
git-receiver: splitted/reimplemented and tested shell command parser
Diffstat (limited to 'tests/blogc-git-receiver')
-rw-r--r--tests/blogc-git-receiver/check_shell_command_parser.c244
1 files changed, 244 insertions, 0 deletions
diff --git a/tests/blogc-git-receiver/check_shell_command_parser.c b/tests/blogc-git-receiver/check_shell_command_parser.c
new file mode 100644
index 0000000..9d0e282
--- /dev/null
+++ b/tests/blogc-git-receiver/check_shell_command_parser.c
@@ -0,0 +1,244 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2015-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file LICENSE.
+ */
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <stdlib.h>
+#include "../../src/blogc-git-receiver/shell-command-parser.h"
+
+
+static void
+test_shell_command_parse(void **state)
+{
+ char *t;
+ assert_null(bgr_shell_command_parse(""));
+ assert_null(bgr_shell_command_parse("bola"));
+ assert_null(bgr_shell_command_parse("bola guda"));
+ assert_null(bgr_shell_command_parse("bola 'guda'"));
+ t = bgr_shell_command_parse("git-receive-pack 'bola.git'");
+ assert_string_equal(t, "bola.git");
+ free(t);
+ t = bgr_shell_command_parse("git-upload-pack 'bolaa.git'");
+ assert_string_equal(t, "bolaa.git");
+ free(t);
+ t = bgr_shell_command_parse("git-upload-archive 'bolab.git'");
+ assert_string_equal(t, "bolab.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/bola1.git'");
+ assert_string_equal(t, "bola1.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/bola2.git/'");
+ assert_string_equal(t, "bola2.git/");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack 'bola3.git/'");
+ assert_string_equal(t, "bola3.git/");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack 'foo/bola.git'");
+ assert_string_equal(t, "foo/bola.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/foo/bola1.git'");
+ assert_string_equal(t, "foo/bola1.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/foo/bola2.git/'");
+ assert_string_equal(t, "foo/bola2.git/");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack 'foo/bola3.git/'");
+ assert_string_equal(t, "foo/bola3.git/");
+ free(t);
+
+ t = bgr_shell_command_parse("git-receive-pack ''\\''bola.git'");
+ assert_string_equal(t, "'bola.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack ''\\''/bola1.git'");
+ assert_string_equal(t, "'/bola1.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack ''\\''/bola2.git/'");
+ assert_string_equal(t, "'/bola2.git/");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack ''\\''bola3.git/'");
+ assert_string_equal(t, "'bola3.git/");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack ''\\''foo/bola.git'");
+ assert_string_equal(t, "'foo/bola.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack ''\\''/foo/bola1.git'");
+ assert_string_equal(t, "'/foo/bola1.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack ''\\''/foo/bola2.git/'");
+ assert_string_equal(t, "'/foo/bola2.git/");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack ''\\''foo/bola3.git/'");
+ assert_string_equal(t, "'foo/bola3.git/");
+ free(t);
+
+ t = bgr_shell_command_parse("git-receive-pack 'bola.git'\\'''");
+ assert_string_equal(t, "bola.git'");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/bola1.git'\\'''");
+ assert_string_equal(t, "bola1.git'");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/bola2.git/'\\'''");
+ assert_string_equal(t, "bola2.git/'");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack 'bola3.git/'\\'''");
+ assert_string_equal(t, "bola3.git/'");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack 'foo/bola.git'\\'''");
+ assert_string_equal(t, "foo/bola.git'");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/foo/bola1.git'\\'''");
+ assert_string_equal(t, "foo/bola1.git'");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/foo/bola2.git/'\\'''");
+ assert_string_equal(t, "foo/bola2.git/'");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack 'foo/bola3.git/'\\'''");
+ assert_string_equal(t, "foo/bola3.git/'");
+ free(t);
+
+ t = bgr_shell_command_parse("git-receive-pack 'bo'\\''la.git'");
+ assert_string_equal(t, "bo'la.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/bo'\\''la1.git'");
+ assert_string_equal(t, "bo'la1.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/bo'\\''la2.git/'");
+ assert_string_equal(t, "bo'la2.git/");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack 'bo'\\''la3.git/'");
+ assert_string_equal(t, "bo'la3.git/");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack 'foo/bo'\\''la.git'");
+ assert_string_equal(t, "foo/bo'la.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/foo/bo'\\''la1.git'");
+ assert_string_equal(t, "foo/bo'la1.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/foo/bo'\\''la2.git/'");
+ assert_string_equal(t, "foo/bo'la2.git/");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack 'foo/bo'\\''la3.git/'");
+ assert_string_equal(t, "foo/bo'la3.git/");
+ free(t);
+
+ t = bgr_shell_command_parse("git-receive-pack ''\\!'bola.git'");
+ assert_string_equal(t, "!bola.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack ''\\!'/bola1.git'");
+ assert_string_equal(t, "!/bola1.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack ''\\!'/bola2.git/'");
+ assert_string_equal(t, "!/bola2.git/");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack ''\\!'bola3.git/'");
+ assert_string_equal(t, "!bola3.git/");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack ''\\!'foo/bola.git'");
+ assert_string_equal(t, "!foo/bola.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack ''\\!'/foo/bola1.git'");
+ assert_string_equal(t, "!/foo/bola1.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack ''\\!'/foo/bola2.git/'");
+ assert_string_equal(t, "!/foo/bola2.git/");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack ''\\!'foo/bola3.git/'");
+ assert_string_equal(t, "!foo/bola3.git/");
+ free(t);
+
+ t = bgr_shell_command_parse("git-receive-pack 'bola.git'\\!''");
+ assert_string_equal(t, "bola.git!");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/bola1.git'\\!''");
+ assert_string_equal(t, "bola1.git!");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/bola2.git/'\\!''");
+ assert_string_equal(t, "bola2.git/!");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack 'bola3.git/'\\!''");
+ assert_string_equal(t, "bola3.git/!");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack 'foo/bola.git'\\!''");
+ assert_string_equal(t, "foo/bola.git!");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/foo/bola1.git'\\!''");
+ assert_string_equal(t, "foo/bola1.git!");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/foo/bola2.git/'\\!''");
+ assert_string_equal(t, "foo/bola2.git/!");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack 'foo/bola3.git/'\\!''");
+ assert_string_equal(t, "foo/bola3.git/!");
+ free(t);
+
+ t = bgr_shell_command_parse("git-receive-pack 'bo'\\!'la.git'");
+ assert_string_equal(t, "bo!la.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/bo'\\!'la1.git'");
+ assert_string_equal(t, "bo!la1.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/bo'\\!'la2.git/'");
+ assert_string_equal(t, "bo!la2.git/");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack 'bo'\\!'la3.git/'");
+ assert_string_equal(t, "bo!la3.git/");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack 'foo/bo'\\!'la.git'");
+ assert_string_equal(t, "foo/bo!la.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/foo/bo'\\!'la1.git'");
+ assert_string_equal(t, "foo/bo!la1.git");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack '/foo/bo'\\!'la2.git/'");
+ assert_string_equal(t, "foo/bo!la2.git/");
+ free(t);
+ t = bgr_shell_command_parse("git-receive-pack 'foo/bo'\\!'la3.git/'");
+ assert_string_equal(t, "foo/bo!la3.git/");
+ free(t);
+}
+
+
+static void
+test_shell_quote(void **state)
+{
+ char *t;
+ t = bgr_shell_quote(NULL);
+ assert_string_equal(t, "''");
+ free(t);
+ t = bgr_shell_quote("!bola");
+ assert_string_equal(t, "''\\!'bola'");
+ free(t);
+ t = bgr_shell_quote("'bola");
+ assert_string_equal(t, "''\\''bola'");
+ free(t);
+ t = bgr_shell_quote("bo!bola");
+ assert_string_equal(t, "'bo'\\!'bola'");
+ free(t);
+ t = bgr_shell_quote("bo'bola");
+ assert_string_equal(t, "'bo'\\''bola'");
+ free(t);
+ t = bgr_shell_quote("bola!");
+ assert_string_equal(t, "'bola'\\!''");
+ free(t);
+ t = bgr_shell_quote("bola'");
+ assert_string_equal(t, "'bola'\\'''");
+ free(t);
+}
+
+
+int
+main(void)
+{
+ const UnitTest tests[] = {
+ unit_test(test_shell_command_parse),
+ unit_test(test_shell_quote),
+ };
+ return run_tests(tests);
+}