def _check_empty_script(filename, message, expect_fail):
    """Returns a script check that checks for empty diagnostics in a file.

    Args:
      filename: name of file containing diagnostic output.
      message: message to print when there are unexpected findings.
        message may be multiline.
      expect_fail: if True expect there to be findings, and invert test status.

    Returns:
      A string that is a shell script for the diagnostic test.
    """
    if expect_fail:
        return """
test -s "$(rlocation ${{TEST_WORKSPACE}}/{})" ||
  {{ echo Expected diagnostics, but found none. ; exit 1 ;}}
""".format(filename)
    else:
        return """
test ! -s "$(rlocation ${{TEST_WORKSPACE}}/{filename})" ||
  {{ cat <<EOF
{message}
EOF
     cat "$(rlocation ${{TEST_WORKSPACE}}/{filename})" ;
     exit 1 ;}}
""".format(filename = filename, message = message)