Skip to content

Instantly share code, notes, and snippets.

@dbrock
Created October 23, 2013 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbrock/7127620 to your computer and use it in GitHub Desktop.
Save dbrock/7127620 to your computer and use it in GitHub Desktop.
Example of the limits of the Bats preprocessor.
# -*- sh -*-
@test "empty input" { diff <<'^D' - <(bin/html </dev/null); }
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
</body>
</html>
^D
@sstephenson
Copy link

Yeah, it could be smarter about single-line test declarations. The preprocessor doesn't touch anything past the first line though, so this should work:

@test "empty input" { 
  diff - <(bin/html </dev/null)
}<<'^D'
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
  </head>
  <body>
  </body>
</html>
^D

@dbrock
Copy link
Author

dbrock commented Oct 23, 2013

Thanks. Good to know that it only touches the first line. And the function redirection is a great workaround to avoid having to put the brace after the heredoc!

I’ll dig in to the parser to see how it works. Lately I’ve been playing around with the function declaration syntax a lot and having a lot of fun with it, using other kinds of compound commands for function bodies instead of the usual { ... }, etc. I kind of like how flexible it is!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment