Skip to content

Commit

Permalink
Tidy up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed May 25, 2021
1 parent 5258802 commit 01c812b
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 16 deletions.
8 changes: 2 additions & 6 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ func cmdMkGPGConfig(ts *testscript.TestScript, neg bool, args []string) {
`encryption = "gpg"`,
`[gpg]`,
` args = [`,
` "--homedir", ` + quote(gpgHomeDir) + `,`,
` "--homedir", ` + strconv.Quote(gpgHomeDir) + `,`,
` "--no-tty",`,
` "--passphrase", ` + quote(passphrase) + `,`,
` "--passphrase", ` + strconv.Quote(passphrase) + `,`,
` "--pinentry-mode", "loopback",`,
` ]`,
}
Expand Down Expand Up @@ -446,10 +446,6 @@ func prependDirToPath(dir, path string) string {
return strings.Join(append([]string{dir}, filepath.SplitList(path)...), string(os.PathListSeparator))
}

func quote(s string) string {
return fmt.Sprintf("%q", s)
}

func setup(env *testscript.Env) error {
var (
binDir = filepath.Join(env.WorkDir, "bin")
Expand Down
2 changes: 1 addition & 1 deletion testdata/scripts/add.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ chezmoi add $HOME${/}.symlink
cmp $CHEZMOISOURCEDIR/symlink_dot_symlink golden/symlink_dot_symlink

# test adding a symlink with a separator
symlink $HOME${/}.symlink2 -> .dir${/}subdir${/}file
symlink $HOME/.symlink2 -> .dir/subdir/file
chezmoi add $HOME${/}.symlink2
cmp $CHEZMOISOURCEDIR/symlink_dot_symlink2 golden/symlink_dot_symlink

Expand Down
2 changes: 1 addition & 1 deletion testdata/scripts/applychmod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mkhomedir
mksourcedir

# test change file mode
chmod 777 $HOME${/}.file
chmod 777 $HOME/.file
chezmoi apply --force
cmpmod 666 $HOME/.file

Expand Down
2 changes: 1 addition & 1 deletion testdata/scripts/merge.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ stdout ^${HOME@R}/\.file\s+${CHEZMOISOURCEDIR@R}/dot_file\s+${WORK@R}/.*/\.file$
# test that chezmoi merge falls back to a two-way merge when the template is invalid
# FIXME the following test fails
# chezmoi merge $HOME${/}.invalid_template
# stdout ^${HOME@R}/\.invalid_template\s+${CHEZMOISOURCEDIR}/dot_invalid_template\.tmpl$
# stdout ^${HOME@R}/\.invalid_template\s+$CHEZMOISOURCEDIR/dot_invalid_template\.tmpl$

-- bin/vimdiff --
#!/bin/sh
Expand Down
6 changes: 3 additions & 3 deletions testdata/scripts/re-add.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ mksourcedir

# test that chezmoi re-add adds all modified files
chezmoi apply --force
edit $HOME${/}.file
edit $HOME${/}.dir/file
edit $HOME${/}.dir/subdir/file
edit $HOME/.file
edit $HOME/.dir/file
edit $HOME/.dir/subdir/file
chezmoi re-add
grep '# edited' $CHEZMOISOURCEDIR/dot_file
grep '# edited' $CHEZMOISOURCEDIR/dot_dir/file
Expand Down
6 changes: 3 additions & 3 deletions testdata/scripts/symlinks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ chezmoi apply $HOME${/}.template
cmp $HOME/.template $HOME/.file

# test that chezmoi add --template-symlinks replaces absolute symlinks, pointing to files inside home, with templates
symlink ${HOME}${/}.symlink_absolute -> $HOME/.dir/subdir/file
symlink $HOME/.symlink_absolute -> $HOME/.dir/subdir/file
chezmoi add --template-symlinks $HOME${/}.symlink_absolute
cmp $CHEZMOISOURCEDIR/symlink_dot_symlink_absolute.tmpl golden/symlink_dot_symlink_absolute.tmpl

# test that chezmoi add --template-symlinks replaces absolute symlinks, pointing to files inside the source directory, with templates
symlink $HOME${/}.symlink_source -> $CHEZMOISOURCEDIR/.dir/subdir/file
symlink $HOME/.symlink_source -> $CHEZMOISOURCEDIR/.dir/subdir/file
chezmoi add --template-symlinks $HOME${/}.symlink_source
cmp $CHEZMOISOURCEDIR/symlink_dot_symlink_source.tmpl golden/symlink_dot_symlink_source.tmpl

chhome home2/user

# test that chezmoi add reads add.templateSymlinks from the config file
symlink ${HOME}${/}.symlink_absolute -> $HOME/.dir/subdir/file
symlink $HOME/.symlink_absolute -> $HOME/.dir/subdir/file
chezmoi add --template-symlinks $HOME${/}.symlink_absolute
cmp $CHEZMOISOURCEDIR/symlink_dot_symlink_absolute.tmpl golden/symlink_dot_symlink_absolute.tmpl

Expand Down
2 changes: 1 addition & 1 deletion testdata/scripts/templatefuncs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ stdout a${/}b

# test lookPath template function
chezmoi execute-template '{{ lookPath "go" }}'
stdout go${exe}
stdout go$exe

# test stat template function
chezmoi execute-template '{{ (stat ".").isDir }}'
Expand Down

0 comments on commit 01c812b

Please sign in to comment.