(CommandList
  children: [
    (Assignment
      keyword: Assign_None
      pairs: [
        (assign_pair
          lhs: (LhsName name:test_description)
          op: Equal
          rhs: {(SQ <'credential-store tests'>)}
          spids: [4]
        )
      ]
      spids: [4]
    )
    (C {(.)} {(./test-lib.sh)})
    (C {(.)} {(DQ ($ VSub_Name '$TEST_DIRECTORY')) (/lib-credential.sh)})
    (C {(helper_test)} {(store)})
    (C {(test_expect_success)} {(SQ <'when xdg file does not exist, xdg file not created'>)} 
      {
        (SQ <'\n'> <'\ttest_path_is_missing "$HOME/.config/git/credentials" &&\n'> 
          <'\ttest -s "$HOME/.git-credentials"\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'setup xdg file'>)} 
      {
        (SQ <'\n'> <'\trm -f "$HOME/.git-credentials" &&\n'> <'\tmkdir -p "$HOME/.config/git" &&\n'> 
          <'\t>"$HOME/.config/git/credentials"\n'>
        )
      }
    )
    (C {(helper_test)} {(store)})
    (C {(test_expect_success)} {(SQ <'when xdg file exists, home file not created'>)} 
      {
        (SQ <'\n'> <'\ttest -s "$HOME/.config/git/credentials" &&\n'> 
          <'\ttest_path_is_missing "$HOME/.git-credentials"\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'setup custom xdg file'>)} 
      {
        (SQ <'\n'> <'\trm -f "$HOME/.git-credentials" &&\n'> 
          <'\trm -f "$HOME/.config/git/credentials" &&\n'> <'\tmkdir -p "$HOME/xdg/git" &&\n'> <'\t>"$HOME/xdg/git/credentials"\n'>
        )
      }
    )
    (Assignment
      keyword: Assign_None
      pairs: [
        (assign_pair
          lhs: (LhsName name:XDG_CONFIG_HOME)
          op: Equal
          rhs: {(DQ ($ VSub_Name '$HOME') (/xdg))}
          spids: [86]
        )
      ]
      spids: [86]
    )
    (C {(export)} {(XDG_CONFIG_HOME)})
    (C {(helper_test)} {(store)})
    (C {(unset)} {(XDG_CONFIG_HOME)})
    (C {(test_expect_success)} {(SQ <'if custom xdg file exists, home and xdg files not created'>)} 
      {
        (SQ <'\n'> <'\ttest_when_finished "rm -f $HOME/xdg/git/credentials" &&\n'> 
          <'\ttest -s "$HOME/xdg/git/credentials" &&\n'> <'\ttest_path_is_missing "$HOME/.git-credentials" &&\n'> 
          <'\ttest_path_is_missing "$HOME/.config/git/credentials"\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'get: use home file if both home and xdg files have matches'>)} 
      {
        (SQ <'\n'> <'\techo "https://home-user:home-pass@example.com" >"$HOME/.git-credentials" &&\n'> 
          <'\tmkdir -p "$HOME/.config/git" &&\n'> <'\techo "https://xdg-user:xdg-pass@example.com" >"$HOME/.config/git/credentials" &&\n'> 
          <'\tcheck fill store <<-\\EOF\n'> <'\tprotocol=https\n'> <'\thost=example.com\n'> <'\t--\n'> <'\tprotocol=https\n'> 
          <'\thost=example.com\n'> <'\tusername=home-user\n'> <'\tpassword=home-pass\n'> <'\t--\n'> <'\tEOF\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'get: use xdg file if home file has no matches'>)} 
      {
        (SQ <'\n'> <'\t>"$HOME/.git-credentials" &&\n'> <'\tmkdir -p "$HOME/.config/git" &&\n'> 
          <'\techo "https://xdg-user:xdg-pass@example.com" >"$HOME/.config/git/credentials" &&\n'> <'\tcheck fill store <<-\\EOF\n'> <'\tprotocol=https\n'> <'\thost=example.com\n'> <'\t--\n'> 
          <'\tprotocol=https\n'> <'\thost=example.com\n'> <'\tusername=xdg-user\n'> <'\tpassword=xdg-pass\n'> <'\t--\n'> <'\tEOF\n'>
        )
      }
    )
    (C {(test_expect_success)} {(POSIXPERM) (Lit_Comma ',') (SANITY)} 
      {(SQ <'get: use xdg file if home file is unreadable'>)} 
      {
        (SQ <'\n'> <'\techo "https://home-user:home-pass@example.com" >"$HOME/.git-credentials" &&\n'> 
          <'\tchmod -r "$HOME/.git-credentials" &&\n'> <'\tmkdir -p "$HOME/.config/git" &&\n'> 
          <'\techo "https://xdg-user:xdg-pass@example.com" >"$HOME/.config/git/credentials" &&\n'> <'\tcheck fill store <<-\\EOF\n'> <'\tprotocol=https\n'> <'\thost=example.com\n'> <'\t--\n'> 
          <'\tprotocol=https\n'> <'\thost=example.com\n'> <'\tusername=xdg-user\n'> <'\tpassword=xdg-pass\n'> <'\t--\n'> <'\tEOF\n'>
        )
      }
    )
    (C {(test_expect_success)} 
      {(SQ <'store: if both xdg and home files exist, only store in home file'>)} 
      {
        (SQ <'\n'> <'\t>"$HOME/.git-credentials" &&\n'> <'\tmkdir -p "$HOME/.config/git" &&\n'> 
          <'\t>"$HOME/.config/git/credentials" &&\n'> <'\tcheck approve store <<-\\EOF &&\n'> <'\tprotocol=https\n'> <'\thost=example.com\n'> 
          <'\tusername=store-user\n'> <'\tpassword=store-pass\n'> <'\tEOF\n'> 
          <'\techo "https://store-user:store-pass@example.com" >expected &&\n'> <'\ttest_cmp expected "$HOME/.git-credentials" &&\n'> 
          <'\ttest_must_be_empty "$HOME/.config/git/credentials"\n'>
        )
      }
    )
    (C {(test_expect_success)} {(SQ <'erase: erase matching credentials from both xdg and home files'>)} 
      {
        (SQ <'\n'> <'\techo "https://home-user:home-pass@example.com" >"$HOME/.git-credentials" &&\n'> 
          <'\tmkdir -p "$HOME/.config/git" &&\n'> <'\techo "https://xdg-user:xdg-pass@example.com" >"$HOME/.config/git/credentials" &&\n'> 
          <'\tcheck reject store <<-\\EOF &&\n'> <'\tprotocol=https\n'> <'\thost=example.com\n'> <'\tEOF\n'> 
          <'\ttest_must_be_empty "$HOME/.git-credentials" &&\n'> <'\ttest_must_be_empty "$HOME/.config/git/credentials"\n'>
        )
      }
    )
    (C {(test_done)})
  ]
)