From 2c1b2eaaef8726c71648b4a115fbe628f28d6b4b Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 7 Oct 2016 01:48:16 +0200 Subject: git-receiver: splitted/reimplemented and tested shell command parser --- .../check_shell_command_parser.c | 244 +++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 tests/blogc-git-receiver/check_shell_command_parser.c (limited to 'tests') 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 + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#include +#include +#include +#include +#include +#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); +} -- cgit v1.2.3-18-g5258