varnishtest "Various VCL compiler coverage tests"

shell "true > ${tmpdir}/_varnishtest_empty_file"

feature dns

varnish v1 -vcl {
	backend b { .host = "127.0.0.1"; }
	include "${tmpdir}/_varnishtest_empty_file" ;
}

varnish v1 -errvcl {include <string> not followed by semicolon.} {
	backend b { .host = "127.0.0.1"; }
	include "${tmpdir}/_varnishtest_empty_file" |
}

shell "rm -f ${tmpdir}/_varnishtest_empty_file"

varnish v1 -errvcl {include not followed by string constant.} {
	backend b { .host = "127.0.0.1"; }
	include <<
}

varnish v1 -errvcl {include not followed by string constant.} {
	/* token test */
	error lookup hash pipe pass fetch deliver discard keep restart
	include
	if else elseif elsif
	++ -- && || <= == != >= >> << += -= *= /=
	{ } ( ) * + - / % > < = ; ! & . | ~ ,
}

varnish v1 -errvcl {Unknown time unit 'k'.  Legal are 'ms', 's', 'm', 'h', 'd', 'w' and 'y'} {
	backend b { .host = "127.0.0.1"; }
	sub vcl_backend_response { set beresp.ttl = 1. k; }
}

varnish v1 -errvcl {Operator > not possible on BACKEND} {
	backend a { .host = "127.0.0.1"; }
	backend b { .host = "127.0.0.1"; }
	sub vcl_recv { if (a > b) { } }
}

varnish v1 -errvcl {Symbol not found: 'req.foo'} {
	backend b { .host = "127.0.0.1"; }
	sub vcl_hash { if (req.foo != "bar") { } }
}

varnish v1 -errvcl {Symbol not found: 'foo.bar'} {
	sub vcl_init {
		new bar = foo.bar();
	}
}

varnish v1 -errvcl {Cannot be set in method 'vcl_pipe'} {
	backend b { .host = "127.0.0.1"; }
	sub vcl_pipe {
		set bereq.first_byte_timeout = 10s;
	}
}

varnish v1 -errvcl {Cannot be set in method 'vcl_pipe'.} {
	backend b { .host = "127.0.0.1"; }
	sub vcl_pipe {
		set bereq.between_bytes_timeout = 10s;
	}
}

varnish v1 -errvcl {Symbol not found: 'c'} {
	backend b { .host = "127.0.0.1"; }
	sub vcl_backend_response {
		if (beresp.backend == c) {
			set beresp.ttl = 1h;
		}
	}
}

varnish v1 -errvcl {Regexp compilation error:} {
	backend b { .host = "127.0.0.1"; }
	sub vcl_recv {
		if (req.url ~ "[a") {}
	}
}

varnish v1 -errvcl {resolves to too many addresses} {
	backend b { .host = "127.0.0.1"; }
	sub vcl_recv {
		if (remote.ip == "varnish-cache.org") {}
	}
}

varnish v1 -errvcl {Symbol 'foo' has wrong type (instance):} {
	import directors;
	backend b { .host = "127.0.0.1"; }

	sub vcl_init {
		new foo = directors.shard();
	}
	sub vcl_recv {
		if (client.ip ~ foo) {
			return (synth(200));
		}
	}
}

varnish v1 -syntax 4.0 -errvcl {Undefined acl foo} {
	import directors;
	backend b { .host = "127.0.0.1"; }

	sub vcl_init {
		new foo = directors.shard();
	}
	sub vcl_recv {
		if (client.ip ~ foo) {
			return (synth(200));
		}
	}
}

# 'foo' overloaded
varnish v1 -syntax 4.0 -errvcl {Symbol not found: 'foo'} {
	backend b { .host = "127.0.0.1"; }

	acl foo {
	    "127.0.0.1"/32;
	}
	sub vcl_init {
		new bar = foo;
	}
}
