# Shell library to run git-daemon in tests. Ends the test early if # GIT_TEST_GIT_DAEMON is not set. # # Usage: # # . ./test-lib.sh # . "$TEST_DIRECTORY"/lib-git-daemon.sh # start_git_daemon # # test_expect_success '...' ' # ... # ' # # test_expect_success ... # # stop_git_daemon # test_done test_tristate GIT_TEST_GIT_DAEMON if test $GIT_TEST_GIT_DAEMON = false { global skip_all := '"git-daemon testing disabled (unset GIT_TEST_GIT_DAEMON to enable)'" test_done } if test_have_prereq !PIPE { test_skip_or_die $GIT_TEST_GIT_DAEMON "file system does not support FIFOs" } global LIB_GIT_DAEMON_PORT := $(LIB_GIT_DAEMON_PORT-${this_test#t}) global GIT_DAEMON_PID := '' global GIT_DAEMON_DOCUMENT_ROOT_PATH := ""$PWD"/repo" global GIT_DAEMON_URL := "git://127.0.0.1:$LIB_GIT_DAEMON_PORT" proc start_git_daemon { if test -n $GIT_DAEMON_PID { error "start_git_daemon already called" } mkdir -p $GIT_DAEMON_DOCUMENT_ROOT_PATH trap 'code=$?; stop_git_daemon; (exit $code); die' EXIT say >&3 "Starting git daemon ...> !3 "Starting git daemon ..." mkfifo git_daemon_output git daemon --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \ --reuseaddr --verbose \ --base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \ @Argv $GIT_DAEMON_DOCUMENT_ROOT_PATH \ > !3 !2 >git_daemon_output & global GIT_DAEMON_PID := $BgPid do { read line <&7 echo >&4 $line> !4 "$line" cat <&7 > !4 & } 7&3 "Stopping git daemon ...> !3 "Stopping git daemon ..." kill $GIT_DAEMON_PID wait $GIT_DAEMON_PID > !3 !2 > !4 global ret := $Status if test_match_signal 15 $Status { error "git daemon exited with status: $ret" } global GIT_DAEMON_PID := '' rm -f git_daemon_output } (CommandList children: [ (C {(test_tristate)} {(GIT_TEST_GIT_DAEMON)}) (If arms: [ (if_arm cond: [(C {(test)} {(DQ ($ VSub_Name "$GIT_TEST_GIT_DAEMON"))} {(Lit_Other "=")} {(false)})] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:skip_all) op: Equal rhs: {(DQ ("git-daemon testing disabled (unset GIT_TEST_GIT_DAEMON to enable)"))} spids: [71] ) ] spids: [71] ) (C {(test_done)}) ] spids: [-1 68] ) ] spids: [-1 79] ) (If arms: [ (if_arm cond: [(C {(test_have_prereq)} {(KW_Bang "!") (PIPE)})] action: [ (C {(test_skip_or_die)} {($ VSub_Name "$GIT_TEST_GIT_DAEMON")} {(DQ ("file system does not support FIFOs"))} ) ] spids: [-1 89] ) ] spids: [-1 100] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LIB_GIT_DAEMON_PORT) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_Hyphen arg_word: { (BracedVarSub token: suffix_op: (StringUnary op_id:VOp1_Pound arg_word:{(t)}) spids: [107 111] ) } ) spids: [104 112] ) } spids: [103] ) ] spids: [103] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:GIT_DAEMON_PID) op:Equal rhs:{(SQ )} spids:[115])] spids: [115] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GIT_DAEMON_DOCUMENT_ROOT_PATH) op: Equal rhs: {(DQ ($ VSub_Name "$PWD")) (/repo)} spids: [117] ) ] spids: [117] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GIT_DAEMON_URL) op: Equal rhs: {(git) (Lit_Other ":") (//127.0.0.1) (Lit_Other ":") ($ VSub_Name "$LIB_GIT_DAEMON_PORT")} spids: [123] ) ] spids: [123] ) (FuncDef name: start_git_daemon body: (BraceGroup children: [ (If arms: [ (if_arm cond: [(C {(test)} {(-n)} {(DQ ($ VSub_Name "$GIT_DAEMON_PID"))})] action: [(C {(error)} {(DQ ("start_git_daemon already called"))})] spids: [-1 149] ) ] spids: [-1 159] ) (C {(mkdir)} {(-p)} {(DQ ($ VSub_Name "$GIT_DAEMON_DOCUMENT_ROOT_PATH"))}) (C {(trap)} {(SQ <"code=$?; stop_git_daemon; (exit $code); die">)} {(EXIT)}) (SimpleCommand words: [{(say)} {(DQ ("Starting git daemon ..."))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(3)} spids:[185])] ) (C {(mkfifo)} {(git_daemon_output)}) (Sentence child: (SimpleCommand words: [ {(git)} {(daemon)} {(--listen) (Lit_Other "=") (127.0.0.1)} {(--port) (Lit_Other "=") (DQ ($ VSub_Name "$LIB_GIT_DAEMON_PORT"))} {(--reuseaddr)} {(--verbose)} {(--base-path) (Lit_Other "=") (DQ ($ VSub_Name "$GIT_DAEMON_DOCUMENT_ROOT_PATH"))} {(DQ ($ VSub_At "$@"))} {(DQ ($ VSub_Name "$GIT_DAEMON_DOCUMENT_ROOT_PATH"))} ] redirects: [ (Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(3)} spids:[238]) (Redir op_id: Redir_Great fd: 2 arg_word: {(git_daemon_output)} spids: [241] ) ] ) terminator: ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GIT_DAEMON_PID) op: Equal rhs: {($ VSub_Bang "$!")} spids: [247] ) ] spids: [247] ) (AndOr children: [ (BraceGroup children: [ (SimpleCommand words: [{(read)} {(line)}] redirects: [(Redir op_id:Redir_LessAnd fd:-1 arg_word:{(7)} spids:[258])] ) (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Name "$line"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(4)} spids:[264])] ) (Sentence child: (SimpleCommand words: [{(cat)}] redirects: [ (Redir op_id: Redir_LessAnd fd: -1 arg_word: {(7)} spids: [274] ) (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(4)} spids: [277] ) ] ) terminator: ) ] redirects: [ (Redir op_id: Redir_Less fd: 7 arg_word: {(git_daemon_output)} spids: [285] ) ] spids: [251] ) (If arms: [ (if_arm cond: [ (C {(test)} {(x) (DQ (CommandSubPart command_list: (CommandList children: [ (C {(expr)} {(DQ ($ VSub_Name "$line"))} {(Lit_Other ":")} { (DQ (EscapedLiteralPart token:) ("[0-9]*") (EscapedLiteralPart token:) (" ") (EscapedLiteralPart token: ) (".*") (EscapedLiteralPart token:) ) } ) ] ) left_token: spids: [302 320] ) ) } {(KW_Bang "!") (Lit_Other "=")} {(x) (DQ ("Ready to rumble"))} ) ] action: [ (C {(kill)} {(DQ ($ VSub_Name "$GIT_DAEMON_PID"))}) (C {(wait)} {(DQ ($ VSub_Name "$GIT_DAEMON_PID"))}) (C {(trap)} {(SQ )} {(EXIT)}) (C {(test_skip_or_die)} {($ VSub_Name "$GIT_TEST_GIT_DAEMON")} {(DQ ("git daemon failed to start"))} ) ] spids: [-1 332] ) ] spids: [-1 369] ) ] op_id: Op_DAmp ) ] spids: [135] ) spids: [131 134] ) (FuncDef name: stop_git_daemon body: (BraceGroup children: [ (If arms: [ (if_arm cond: [(C {(test)} {(-z)} {(DQ ($ VSub_Name "$GIT_DAEMON_PID"))})] action: [(ControlFlow token:)] spids: [-1 392] ) ] spids: [-1 398] ) (C {(trap)} {(SQ )} {(EXIT)}) (SimpleCommand words: [{(say)} {(DQ ("Stopping git daemon ..."))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(3)} spids:[418])] ) (C {(kill)} {(DQ ($ VSub_Name "$GIT_DAEMON_PID"))}) (SimpleCommand words: [{(wait)} {(DQ ($ VSub_Name "$GIT_DAEMON_PID"))}] redirects: [ (Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(3)} spids:[439]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(4)} spids:[442]) ] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ret) op: Equal rhs: {($ VSub_QMark "$?")} spids: [446] ) ] spids: [446] ) (If arms: [ (if_arm cond: [(C {(test_match_signal)} {(15)} {($ VSub_QMark "$?")})] action: [(C {(error)} {(DQ ("git daemon exited with status: ") ($ VSub_Name "$ret"))})] spids: [-1 459] ) ] spids: [-1 470] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GIT_DAEMON_PID) op: Equal rhs: {(SQ )} spids: [473] ) ] spids: [473] ) (C {(rm)} {(-f)} {(git_daemon_output)}) ] spids: [378] ) spids: [374 377] ) ] )