# HG changeset patch # User Manuel Jacob # Date 1592780602 -7200 # Node ID ce5ebd9c859bd57c9e869ea75afb02675a087049 # Parent 02804d8bac313835772c25bab5f7521561af51b8 tests: add a test determining the branch and topic like the Zsh prompt does it A patch was sent to the Zsh developers to change the prompt to include the name of the topic if it is set. It was agreed that I submit a test case to the topic extension that fails if the format of the files used by Zsh changes. The current version of the patch can be found here: https://www.zsh.org/mla/workers/2020/msg00910.html diff -r 02804d8bac31 -r ce5ebd9c859b tests/test-topic-shell-prompt.t --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-topic-shell-prompt.t Mon Jun 22 01:03:22 2020 +0200 @@ -0,0 +1,29 @@ + $ . $TESTDIR/testlib/topic_setup.sh + +Code logically equivalent to the following is used in Zsh to show the branch +and topic (if set) in the prompt. If the format of the files is changed in a +way that it breaks the test, a mail should be sent to zsh-workers@zsh.org. + + $ get_branch_like_zsh() { + > branchfile=".hg/branch" + > topicfile=".hg/topic" + > if [ -r "${branchfile}" ] ; then + > r_branch=$(cat "${branchfile}") + > fi + > if [ -f "${topicfile}" ] && [ -r "${topicfile}" ] && [ -s "${topicfile}" ] ; then + > IFS= read -r REPLY < ${topicfile} + > r_branch=${r_branch}:${REPLY} + > fi + > echo $r_branch + > } + + $ hg init + $ hg branch branch -q + $ get_branch_like_zsh + branch + $ hg topic topic -q + $ get_branch_like_zsh + branch:topic + $ hg topic --clear -q + $ get_branch_like_zsh + branch