Import atf 0.22 snapshot 55c21b2c5fb189bbdfccb2b297bfa89236502542

The main improvement is the ability to skip a test that is expected to
fail.
This commit is contained in:
Alan Somers 2021-09-10 17:08:42 -06:00
commit 71a1ae7ceb
5 changed files with 52 additions and 22 deletions

View File

@ -22,7 +22,7 @@
.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.Dd April 5, 2017
.Dd February 23, 2021
.Dt ATF-C 3
.Os
.Sh NAME
@ -35,6 +35,8 @@
.Nm ATF_CHECK_MATCH_MSG ,
.Nm ATF_CHECK_STREQ ,
.Nm ATF_CHECK_STREQ_MSG ,
.Nm ATF_CHECK_INTEQ ,
.Nm ATF_CHECK_INTEQ_MSG ,
.Nm ATF_CHECK_ERRNO ,
.Nm ATF_REQUIRE ,
.Nm ATF_REQUIRE_MSG ,
@ -44,6 +46,8 @@
.Nm ATF_REQUIRE_MATCH_MSG ,
.Nm ATF_REQUIRE_STREQ ,
.Nm ATF_REQUIRE_STREQ_MSG ,
.Nm ATF_REQUIRE_INTEQ ,
.Nm ATF_REQUIRE_INTEQ_MSG ,
.Nm ATF_REQUIRE_ERRNO ,
.Nm ATF_TC ,
.Nm ATF_TC_BODY ,
@ -96,8 +100,10 @@
.Fn ATF_CHECK_EQ_MSG "expected_expression" "actual_expression" "fail_msg_fmt" ...
.Fn ATF_CHECK_MATCH "regexp" "string"
.Fn ATF_CHECK_MATCH_MSG "regexp" "string" "fail_msg_fmt" ...
.Fn ATF_CHECK_STREQ "string_1" "string_2"
.Fn ATF_CHECK_STREQ_MSG "string_1" "string_2" "fail_msg_fmt" ...
.Fn ATF_CHECK_STREQ "expected_string" "actual_string"
.Fn ATF_CHECK_STREQ_MSG "expected_string" "actual_string" "fail_msg_fmt" ...
.Fn ATF_CHECK_INTEQ "expected_int" "actual_int"
.Fn ATF_CHECK_INTEQ_MSG "expected_int" "actual_int" "fail_msg_fmt" ...
.Fn ATF_CHECK_ERRNO "expected_errno" "bool_expression"
.Fn ATF_REQUIRE "expression"
.Fn ATF_REQUIRE_MSG "expression" "fail_msg_fmt" ...
@ -107,6 +113,8 @@
.Fn ATF_REQUIRE_MATCH_MSG "regexp" "string" "fail_msg_fmt" ...
.Fn ATF_REQUIRE_STREQ "expected_string" "actual_string"
.Fn ATF_REQUIRE_STREQ_MSG "expected_string" "actual_string" "fail_msg_fmt" ...
.Fn ATF_REQUIRE_INTEQ "expected_int" "actual_int"
.Fn ATF_REQUIRE_INTEQ_MSG "expected_int" "actual_int" "fail_msg_fmt" ...
.Fn ATF_REQUIRE_ERRNO "expected_errno" "bool_expression"
.\" NO_CHECK_STYLE_END
.Fn ATF_TC "name"
@ -494,7 +502,7 @@ and
.Fn ATF_REQUIRE_EQ_MSG
take two expressions and fail if the two evaluated values are not equal.
The common style is to put the expected value in the first parameter and the
actual value in the second parameter.
observed value in the second parameter.
.Pp
.Fn ATF_CHECK_MATCH ,
.Fn ATF_CHECK_MATCH_MSG ,
@ -513,7 +521,16 @@ and
.Fn ATF_REQUIRE_STREQ_MSG
take two strings and fail if the two are not equal character by character.
The common style is to put the expected string in the first parameter and the
actual string in the second parameter.
observed string in the second parameter.
.Pp
.Fn ATF_CHECK_INTEQ ,
.Fn ATF_CHECK_INTEQ_MSG ,
.Fn ATF_REQUIRE_INTEQ
and
.Fn ATF_REQUIRE_INTQ_MSG
take two integers and fail if the two are not equal.
The common style is to put the expected integer in the first parameter and the
observed integer in the second parameter.
.Pp
.Fn ATF_CHECK_ERRNO
and

View File

@ -185,6 +185,25 @@
"%s != %s (%s != %s): " fmt, \
#expected, #actual, expected, actual, ##__VA_ARGS__)
#define ATF_REQUIRE_INTEQ(expected, actual) \
ATF_REQUIRE_MSG((expected) == (actual), "%s != %s (%jd != %jd)", \
#expected, #actual, (intmax_t)(expected), \
(intmax_t)(actual))
#define ATF_CHECK_INTEQ(expected, actual) \
ATF_CHECK_MSG((expected) == (actual), "%s != %s (%jd != %jd)", #expected, \
#actual, (intmax_t)(expected), (intmax_t)(actual))
#define ATF_REQUIRE_INTEQ_MSG(expected, actual, fmt, ...) \
ATF_REQUIRE_MSG((expected) == (actual), "%s != %s (%jd != %jd): " fmt, \
#expected, #actual, (intmax_t)(expected), \
(intmax_t)(actual), ##__VA_ARGS__)
#define ATF_CHECK_INTEQ_MSG(expected, actual, fmt, ...) \
ATF_CHECK_MSG((expected) == (actual), "%s != %s (%jd != %jd): " fmt, \
#expected, #actual, (intmax_t)(expected), \
(intmax_t)(actual), ##__VA_ARGS__)
#define ATF_REQUIRE_MATCH(regexp, string) \
ATF_REQUIRE_MSG(atf_utils_grep_string("%s", string, regexp), \
"'%s' not matched in '%s'", regexp, string);

View File

@ -381,15 +381,9 @@ pass(struct context *ctx)
static void
skip(struct context *ctx, atf_dynstr_t *reason)
{
if (ctx->expect == EXPECT_PASS) {
create_resfile(ctx, "skipped", -1, reason);
context_close_resfile(ctx);
exit(EXIT_SUCCESS);
} else {
error_in_expect(ctx, "Can only skip a test case when running in "
"expect pass mode");
}
UNREACHABLE;
create_resfile(ctx, "skipped", -1, reason);
context_close_resfile(ctx);
exit(EXIT_SUCCESS);
}
/** Formats a failure/skip reason message.

View File

@ -501,7 +501,7 @@ compare_files(const atf::fs::path& p1, const atf::fs::path& p2)
std::ifstream f2(p2.c_str());
if (!f2)
throw std::runtime_error("Failed to open " + p1.str());
throw std::runtime_error("Failed to open " + p2.str());
for (;;) {
char buf1[512], buf2[512];
@ -512,7 +512,7 @@ compare_files(const atf::fs::path& p1, const atf::fs::path& p2)
f2.read(buf2, sizeof(buf2));
if (f2.bad())
throw std::runtime_error("Failed to read from " + p1.str());
throw std::runtime_error("Failed to read from " + p2.str());
if ((f1.gcount() == 0) && (f2.gcount() == 0)) {
equal = true;

View File

@ -22,7 +22,7 @@
.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.Dd June 08, 2017
.Dd January 27, 2021
.Dt ATF-SH 3
.Os
.Sh NAME
@ -361,21 +361,21 @@ This example demonstrates the use of the very useful
function:
.Bd -literal -offset indent
# Check for silent output
atf_check -s exit:0 -o empty -e empty 'true'
atf_check -s exit:0 -o empty -e empty true
# Check for silent output and failure
atf_check -s exit:1 -o empty -e empty 'false'
atf_check -s exit:1 -o empty -e empty false
# Check for known stdout and silent stderr
echo foo >expout
atf_check -s exit:0 -o file:expout -e empty 'echo foo'
atf_check -s exit:0 -o file:expout -e empty echo foo
# Generate a file for later inspection
atf_check -s exit:0 -o save:stdout -e empty 'ls'
atf_check -s exit:0 -o save:stdout -e empty ls
grep foo ls || atf_fail "foo file not found in listing"
# Or just do the match along the way
atf_check -s exit:0 -o match:"^foo$" -e empty 'ls'
atf_check -s exit:0 -o match:"^foo$" -e empty ls
.Ed
.Sh SEE ALSO
.Xr atf-check 1 ,