vtest "Test relative to vcl_path, dot-include and absolute includes"

# relative plain
shell "true > ${tmpdir}/_start.vcl"
vinyl v1 -arg "-p vcl_path=${tmpdir}" -vcl {
	backend b { .host = "${localhost}"; }
	include "_start.vcl" ;
}

# absolute include
vinyl v1 -vcl {
	backend b { .host = "${localhost}"; }
	include "${tmpdir}/_start.vcl" ;
}

# absolute -> relative include
shell "mkdir -p ${tmpdir}/1/2/3"
shell "true  > ${tmpdir}/1/2/b.vcl"
shell "echo 'include \"./2/b.vcl\";' > ${tmpdir}/1/a.vcl"
vinyl v1 -vcl {
	backend b { .host = "${localhost}"; }
	include "${tmpdir}/1/a.vcl" ;
}

# same but relative to vcl_path
shell "echo 'include \"1/2/b.vcl\";' > ${tmpdir}/1/ab.vcl"
vinyl v1 -vcl {
	backend b { .host = "${localhost}"; }
	include "1/ab.vcl" ;
}

# dot-relative -> relative
vinyl v1 -vcl {
	backend b { .host = "${localhost}"; }
	include "1/a.vcl" ;
}

# relative -> relative -> relative
shell "echo 'include \"./3/c.vcl\";' > ${tmpdir}/1/2/b.vcl"
shell "true  > ${tmpdir}/1/2/3/c.vcl"
vinyl v1 -vcl {
	backend b { .host = "${localhost}"; }
	include "1/a.vcl" ;
}

# relative -> absolute
shell "echo 'include \"${tmpdir}/1/2/3/c.vcl\";' > ${tmpdir}/1/aa.vcl"
vinyl v1 -vcl {
	backend b { .host = "${localhost}"; }
	include "1/aa.vcl" ;
}

# relative -> absolute -> relative
shell "echo 'include \"${tmpdir}/1/2/b.vcl\";' > ${tmpdir}/1/aaa.vcl"
vinyl v1 -vcl {
	backend b { .host = "${localhost}"; }
	include "1/aaa.vcl" ;
}

# includes and parses out
shell "echo 'zool' > ${tmpdir}/1/2/3/c.vcl"
vinyl v1 -errvcl {Found: 'zool' at} {
	backend b { .host = "${localhost}"; }
	include "1/a.vcl";
}

shell "rm -f ${tmpdir}/a"
shell "rm -f ${tmpdir}/_start.vcl"

vinyl v1 -errvcl {needs absolute filename of including file.} {
	include "./foobar";
}
