[!windows] chmod 755 bin/chezmoi-output-test
[windows] unix2dos bin/chezmoi-output-test.cmd

# test ioreg template function
[darwin] chezmoi execute-template '{{ index ioreg "IOKitBuildVersion" }}'
[darwin] stdout 'Darwin Kernel Version'

# test include template function with absolute path
#
# this test is disabled on Windows because the backslashes in Windows paths are
# interpreted as a escape characters in the string constant, which breaks the
# test
#
# FIXME fix this test on Windows
[!windows] exec echo {{ "$HOME/.include" }}
[!windows] stdin stdout
[!windows] chezmoi execute-template
[!windows] cmpenv stdout golden/include-abspath

# test include template function with relative paths
chezmoi execute-template '{{ include ".include" }}'
cmp stdout golden/include-relpath

# test joinPath template function
chezmoi execute-template '{{ joinPath "a" "b" }}'
stdout a${/}b

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

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

# test that the output template function returns a command's output
chezmoi execute-template '{{ output "chezmoi-output-test" "arg" | trim }}'
stdout arg

# test that the output template function fails if the command fails
! chezmoi execute-template '{{ output "false" }}'

-- bin/chezmoi-output-test --
#!/bin/sh

echo "$*"
-- bin/chezmoi-output-test.cmd --
@echo off
setlocal
set out=%*
set out=%out:\=%
echo %out%
endlocal
-- golden/include-abspath --
$HOME/.include
-- golden/include-relpath --
# contents of ~/.local/share/chezmoi/.include
-- home/user/.include --
# contents of $HOME/.include
-- home/user/.local/share/chezmoi/.include --
# contents of ~/.local/share/chezmoi/.include
