# test that chezmoi source-path returns the source directory
chezmoi source-path
stdout ^${CHEZMOISOURCEDIR@R}$

# test that chezmoi source-path target returns the path to a target's source file
chezmoi source-path $HOME${/}.file
stdout ^${CHEZMOISOURCEDIR@R}/dot_file$

# test that chezmoi source-path returns an error if the target is not in the source state
! chezmoi source-path $HOME${/}.newfile
stderr 'not in source state'

# test that chezmoi source-path returns an error if the target is not in the destination directory
! chezmoi source-path $WORK${/}etc${/}passwd
stderr 'not in'

chhome home2/user

# test that chezmoi source-path target returns the path the target's source file when .chezmoiroot is used
chezmoi source-path $HOME${/}.file
stdout /home/dot_file$

-- home/user/.local/share/chezmoi/dot_file --
# contents of .file
-- home2/user/.local/share/chezmoi/.chezmoiroot --
home
-- home2/user/.local/share/chezmoi/home/dot_file --
# contents of .file
