#!/bin/sh # global test_description := ''git web--browse basic tests This test checks that git web--browse can handle various valid URLs.'' source ./test-lib.sh proc test_web_browse { # browser=$1 url=$2 git web--browse --browser="$1" $2 >actual && tr -d '\015' text && test_cmp expect text } test_expect_success \ 'URL with an ampersand in it' ' echo http://example.com/foo\&bar >expect && git config browser.custom.cmd echo && test_web_browse custom http://example.com/foo\&bar ' test_expect_success \ 'URL with a semi-colon in it' ' echo http://example.com/foo\;bar >expect && git config browser.custom.cmd echo && test_web_browse custom http://example.com/foo\;bar ' test_expect_success \ 'URL with a hash in it' ' echo http://example.com/foo#bar >expect && git config browser.custom.cmd echo && test_web_browse custom http://example.com/foo#bar ' test_expect_success \ 'browser paths are properly quoted' ' echo fake: http://example.com/foo >expect && cat >"fake browser" <<-\EOF && #!/bin/sh echo fake: "$@" EOF chmod +x "fake browser" && git config browser.w3m.path "$(pwd)/fake browser" && test_web_browse w3m http://example.com/foo ' test_expect_success \ 'browser command allows arbitrary shell code' ' echo "arg: http://example.com/foo" >expect && git config browser.custom.cmd " f() { for i in \"\$@\"; do echo arg: \$i done } f" && test_web_browse custom http://example.com/foo ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: { (SQ <"git web--browse basic tests\n"> <"\n"> <"This test checks that git web--browse can handle various valid URLs."> ) } spids: [7] ) ] spids: [7] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: test_web_browse body: (BraceGroup children: [ (AndOr children: [ (SimpleCommand words: [ {(git)} {(web--browse)} {(--browser) (Lit_Other "=") (DQ ($ VSub_Number "$1"))} {(DQ ($ VSub_Number "$2"))} ] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(actual)} spids:[46])] ) (AndOr children: [ (SimpleCommand words: [{(tr)} {(-d)} {(SQ <"\\015">)}] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(actual)} spids: [60] ) (Redir op_id: Redir_Great fd: -1 arg_word: {(text)} spids: [63] ) ] ) (C {(test_cmp)} {(expect)} {(text)}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [25] ) spids: [20 24] ) (C {(test_expect_success)} {(SQ <"URL with an ampersand in it">)} { (SQ <"\n"> <"\techo http://example.com/foo\\&bar >expect &&\n"> <"\tgit config browser.custom.cmd echo &&\n"> <"\ttest_web_browse custom http://example.com/foo\\&bar\n"> ) } ) (C {(test_expect_success)} {(SQ <"URL with a semi-colon in it">)} { (SQ <"\n"> <"\techo http://example.com/foo\\;bar >expect &&\n"> <"\tgit config browser.custom.cmd echo &&\n"> <"\ttest_web_browse custom http://example.com/foo\\;bar\n"> ) } ) (C {(test_expect_success)} {(SQ <"URL with a hash in it">)} { (SQ <"\n"> <"\techo http://example.com/foo#bar >expect &&\n"> <"\tgit config browser.custom.cmd echo &&\n"> <"\ttest_web_browse custom http://example.com/foo#bar\n"> ) } ) (C {(test_expect_success)} {(SQ <"browser paths are properly quoted">)} { (SQ <"\n"> <"\techo fake: http://example.com/foo >expect &&\n"> <"\tcat >\"fake browser\" <<-\\EOF &&\n"> <"\t#!/bin/sh\n"> <"\techo fake: \"$@\"\n"> <"\tEOF\n"> <"\tchmod +x \"fake browser\" &&\n"> <"\tgit config browser.w3m.path \"$(pwd)/fake browser\" &&\n"> <"\ttest_web_browse w3m http://example.com/foo\n"> ) } ) (C {(test_expect_success)} {(SQ <"browser command allows arbitrary shell code">)} { (SQ <"\n"> <"\techo \"arg: http://example.com/foo\" >expect &&\n"> <"\tgit config browser.custom.cmd \"\n"> <"\t\tf() {\n"> <"\t\t\tfor i in \\\"\\$@\\\"; do\n"> <"\t\t\t\techo arg: \\$i\n"> <"\t\t\tdone\n"> <"\t\t}\n"> <"\t\tf\" &&\n"> <"\ttest_web_browse custom http://example.com/foo\n"> ) } ) (C {(test_done)}) ] )