cp input.sh input.sh.orig

# Using stdin should use EditorConfig.
stdin input.sh
shfmt
cmp stdout input.sh.golden
! stderr .

# Verify that -filename works well with EditorConfig.
stdin stdin-filename-bash
shfmt

stdin stdin-filename-bash
! shfmt -filename=foo_posix.sh
stderr '^foo_posix.sh:.* arrays are a bash'

# Using a file path should use EditorConfig, including with the use of flags
# like -l.
shfmt input.sh
cmp stdout input.sh.golden
! stderr .

shfmt -l input.sh
stdout 'input\.sh'
! stderr .

# Using any formatting option should skip all EditorConfig usage.
shfmt -p input.sh
cmp stdout input.sh.orig
! stderr .

shfmt -l -p input.sh
! stdout .
! stderr .

shfmt -sr input.sh
cmp stdout input.sh.orig
! stderr .

# Check that EditorConfig files merge properly.
shfmt morespaces/input.sh
cmp stdout morespaces/input.sh.golden
! stderr .

# Check a folder with all other knobs.
shfmt -l otherknobs
! stdout .
! stderr .

# Ignore directories when walking, if they match ignore=true.
shfmt -l ignored
stdout 'regular\.sh'
! stdout 'ignored\.sh'
! stderr .

-- .editorconfig --
root = true

[*]
indent_style = space
indent_size = 3

[*_posix.sh]
shell_variant = posix
-- input.sh --
{
	indented
}
-- input.sh.golden --
{
   indented
}
-- stdin-filename-bash --
array=(
	element
)
-- morespaces/.editorconfig --
[*.sh]
indent_size = 6
-- morespaces/input.sh --
{
	indented
}
-- morespaces/input.sh.golden --
{
      indented
}
-- otherknobs/.editorconfig --
root = true

[*_bash.sh]
shell_variant = bash

[*_mksh.sh]
shell_variant = mksh

[indent.sh]
# check its default; we tested "space" above.

[binary_next_line.sh]
binary_next_line = true

[switch_case_indent.sh]
switch_case_indent = true

[space_redirects.sh]
space_redirects = true

[keep_padding.sh]
keep_padding = true

[function_next_line.sh]
function_next_line = true

-- otherknobs/shell_variant_bash.sh --
array=(elem)
-- otherknobs/shell_variant_mksh.sh --
coprocess |&
-- otherknobs/indent.sh --
{
	indented
}
-- otherknobs/binary_next_line.sh --
foo \
	| bar
-- otherknobs/switch_case_indent.sh --
case "$1" in
	A) echo foo ;;
esac
-- otherknobs/space_redirects.sh --
echo foo > bar
-- otherknobs/keep_padding.sh --
echo  foo    bar
-- otherknobs/function_next_line.sh --
foo()
{
	echo foo
}
-- ignored/.editorconfig --
root = true

[third_party/**]
ignore = true

[1_lone_ignored.sh]
ignore = true

[2_dir_ignored]
ignore = true

-- ignored/third_party/ignored.sh --
bad (syntax
-- ignored/1_lone_ignored.sh
echo   foo
-- ignored/2_dir_ignored/ignored.sh --
echo   foo
-- ignored/3_regular/regular.sh --
echo   foo
