Annotation of wikisrc/tutorials/atf.mdwn, revision 1.6

1.5       jmmv        1: [[!meta title="Creating atf-based tests for NetBSD src"]]
                      2: [[!toc ]]
                      3: 
1.1       jmmv        4: This quick tutorial is an attempt to workaround the lack of proper documentation
                      5: in atf.  The tutorial provides a guideline on how to start creating new test
                      6: programs and/or test cases, how these tests are tied to the NetBSD source tree
                      7: and a short reference of the most commonly used functions.
                      8: 
                      9: You should start by reading the
                     10: [tests(7)](http://netbsd.gw.com/cgi-bin/man-cgi?tests++NetBSD-current) manual
                     11: page, which is probably the only sane document in the whole documentation.  Any
                     12: other attempts at reading the atf-* manual pages are probably doomed unless you
                     13: are already familiar with atf itself and its internals.  Still, you may be able
                     14: to get some useful information out of
                     15: [atf-run(1)](http://netbsd.gw.com/cgi-bin/man-cgi?atf-run++NetBSD-current),
                     16: [atf-report(1)](http://netbsd.gw.com/cgi-bin/man-cgi?atf-report++NetBSD-current),
                     17: [atf-test-program(1)](http://netbsd.gw.com/cgi-bin/man-cgi?atf-test-program++NetBSD-current),
                     18: [atf-c-api(3)](http://netbsd.gw.com/cgi-bin/man-cgi?atf-c-api++NetBSD-current)
                     19: and
                     20: [atf-sh-api(3)](http://netbsd.gw.com/cgi-bin/man-cgi?atf-sh-api++NetBSD-current).
                     21: 
                     22: **IMPORTANT: Do not take anything for granted, SPECIALLY if you have previously
                     23: worked with and/or have seen src/regress/.  Your assumptions are most likely
1.2       jmmv       24: incorrect.**
1.1       jmmv       25: 
1.5       jmmv       26: # Test programs vs. test cases
1.1       jmmv       27: 
                     28: So, what is what and how do you organize your tests?
                     29: 
                     30: A **test case** is a piece of code that exercises a particular functionality of
                     31: another piece of code.  Commonly, test cases validate the outcome of a
                     32: particular source function or class method, the validity of the execution of a
                     33: command with a particular combination of flags/arguments, etc.  Test cases are
                     34: supposed to be very concise, in the sense that they should just be testing *one
                     35: behavior*.
                     36: 
                     37: A **test program** is a binary that collects and exposes a group of test cases.
                     38: Typically, these test programs expose conceptually-related tests or all the
                     39: tests for a particular source file.
                     40: 
                     41: In general, having many test programs with **just one test case** in them is
                     42: **wrong** and smells from the previous layout of src/regress/.  Think about some
                     43: other organization.  And don't blame atf for this separation: this is extremely
                     44: common in (almost?) all other test frameworks and, when used wisely, becomes an
                     45: invaluable classification.
                     46: 
                     47: For example, suppose you have the following fictitious source files for the ls
                     48: tool:
                     49: 
                     50: * bin/ls/fs.c: Provides the list_files() and stat_files() functions.
                     51: 
                     52: * bin/ls/ui.c: Provides the format_columns() function.
                     53: 
                     54: * bin/ls/main.c: The main method for ls.
                     55: 
                     56: Then, you could define the following test programs and test cases:
                     57: 
                     58: * bin/ls/fs_test.c: Provides test cases for list_files and stat_files.  These
                     59:   would be named list_files__empty_directory, list_files__one_file,
                     60:   list_files__multiple_files, stat_files__directory, stat_files__symlink, etc.
                     61: 
                     62: * bin/ls/ui_test.c: Provides test cases for the format_columns function.  These
                     63:   would be named format_columns__no_files, format_columns__multiple_files, etc.
                     64: 
                     65: * bin/ls/integration_test.sh: Provides "black box" test cases for the binary
                     66:   itself.  These would be named lflag, lflag_and_Fflag, no_flags, no_files, etc.
                     67: 
1.2       jmmv       68: Try to keep your test case names as descriptive as possible so that they do not
                     69: require comments to explain what they intend to test.
                     70: 
1.5       jmmv       71: # Test case parts
1.3       jmmv       72: 
                     73: A test case is composed by three parts: the *head*, the *body* and the
                     74: *cleanup*.  Only the body is required; the other two routines are optional.
                     75: 
1.5       jmmv       76: ## The head
1.3       jmmv       77: 
                     78: The *head* is used **for the sole purpose** to define meta-data properties for
                     79: the test case.  (Eventually, this would not be specified programmatically, but
                     80: is how we deal with the information right now.)
                     81: 
                     82: The following properties are commonly useful:
                     83: 
                     84: * descr: A textual description of the purpose of the test case.
                     85: 
                     86: * require.user: Set to 'root' to mark the test case as root-specific.  It is
                     87:   nice not to abuse this; see puffs and rump.
                     88: 
                     89: * use.fs: Set to 'true' if the test case creates temporary files in the "current
                     90:   directory".  Otherwise the atf runtime will isolate the test case in such a
                     91:   way to forbid this, which will misteriously make your test to fail.
                     92: 
1.5       jmmv       93: ## The body
1.3       jmmv       94: 
                     95: The *body* is the actual meat of the test case.  This is just a regular function
                     96: that executes any code you want and calls special atf functions to report
                     97: failures; see below.
                     98: 
                     99: In particular, be aware that the atf run-time **isolates** the execution of
                    100: every test case to prevent side-effects (such as temporary file leftovers,
                    101: in-memory data corruption, etc.).  In particular:
                    102: 
                    103: * A test case is **always executed as a subprocess** that is separate from the
                    104:   head and the cleanup.
                    105: 
                    106: * The current working directory of a test case is changed to a temporary
                    107:   location that gets cleaned up later on automatically.  (Set the use.fs
                    108:   property to true in the head if you need to write to this temporary
                    109:   directory.)
                    110: 
                    111: * The environment of the test case is "sanitized" to get rid of variables that
                    112:   can cause side-effects; e.g. LC_ALL, TZ, etc.
                    113: 
1.5       jmmv      114: # Installation of test programs: the why and the where
1.2       jmmv      115: 
                    116: Test programs get installed into the /usr/tests/ hierarchy.  The main reason for
                    117: doing that is to allow *any* user to test his system and to be able to convince
                    118: himself that everything is working correctly.
                    119: 
                    120: Imagine that you install NetBSD-current on a public-facing machine that has some
                    121: particular hardware only supported in the bleeding-edge source tree.  In this
                    122: scenario, you, as the administrator, could just go into /usr/tests/, run the
                    123: tests and know immediately if everything is working correctly in your
                    124: software+hardware combination or not.  No need to rely on promises from the
                    125: vendor, no need to deal with a source tree, no need to have a compiler
                    126: installed...
                    127: 
                    128: So, that's the theory.  Now, how does this map to our source tree?
                    129: 
                    130: At the moment, the source test programs are located somewhere under src/tests/.
                    131: Say, for example, that you have the src/tests/bin/ls/ui_test.c source file.
                    132: This Makefile in src/tests/bin/ls/ will take this source file and generate a
                    133: ui_test binary.  The Makefile will also generate an Atffile.  Both files (the
                    134: ui_test binary and the Atffile) will later be installed to /usr/tests/bin/ls/
1.1       jmmv      135: 
1.5       jmmv      136: # Adding a new test
1.1       jmmv      137: 
                    138: To add a new *test case* to the source tree, look for any test program in
                    139: src/tests/ that can assimilate it.  If you find such a program, just add the
1.2       jmmv      140: test case to it: no other changes are required so your life is easy.  Otherwise,
                    141: you will have to create a new test program.
1.1       jmmv      142: 
                    143: To add a new *test program* to the source tree:
                    144: 
                    145: 1. Locate the appropriate subdirectory in which to put your test program.  It is
                    146: OK (and **expected**) to have multiple test programs into the same directory.
                    147: **Restrain yourself from creating one directory per test program.**
                    148: 
                    149: If the subdirectory exists:
                    150: 
                    151: 1. Choose a sane name for the test program; the name must not be so specific
                    152:    that it restricts the addition of future test cases into it.
                    153: 
                    154: 1. Create the test program source file using one of the templates below.
                    155:    E.g. src/tests/tutorial/sample_test.c.
                    156: 
                    157: 1. Add the new test program to the Makefile.
                    158: 
                    159: If the subdirectory does not exist:
                    160: 
                    161: 1. Do the same as above.
                    162: 
                    163: 1. Create the Makefile for the directory using the templates below.
                    164: 
                    165: 1. Edit the parent Makefile to recurse into the new subdirectory.
                    166: 
                    167: 1. Edit src/etc/mtree/NetBSD.base.dist to register the new subdirectory.  Your
                    168:    test will be installed under /usr/tests/.
                    169: 
                    170: 1. Edit src/distrib/sets/lists/tests/mi to register the new test program.  Do
                    171:    not forget to add .debug entries if your test program is a C/C++ binary.
                    172: 
1.5       jmmv      173: ## Makefile template
1.1       jmmv      174: 
1.6     ! jmmv      175:     # $NetBSD: atf.mdwn,v 1.5 2010/09/03 15:04:05 jmmv Exp $
1.1       jmmv      176: 
                    177:     .include <bsd.own.mk>
                    178: 
                    179:     # This must always be defined.
                    180:     TESTSDIR= ${TESTSBASE}/bin/ls
                    181: 
                    182:     # Define only the variables you actually need for the directory.
                    183:     TESTS_C+= c1_test c2_test  # Correspond to c1_test.c and c2_test.c.
                    184:     TESTS_SH+= sh1_test sh2_test  # Correspond to sh1_test.c and sh2_test.c
                    185: 
                    186:     # Define only if your tests need any data files.
                    187:     FILESDIR= ${TESTSDIR}
                    188:     FILES= testdata1.txt testdata2.bin  # Any necessary data files.
                    189: 
                    190:     .include <bsd.test.mk>
                    191: 
1.5       jmmv      192: ## Atffile template
1.2       jmmv      193: 
                    194: What is an Atffile?  An Atffile is the atf-run counterpart of a "Makefile".
                    195: Given that atf tests *do not rely on a toolchain*, they cannot use make(1) to
                    196: script their execution as the old tests in src/regress/ did.
                    197: 
                    198: The Atffiles, in general, just provide a list of test programs in a particular
                    199: directory and the list of the subdirectories to descend into.
                    200: 
                    201: Atffiles are automatically generated by bsd.test.mk, so in general you will not
                    202: have to deal with them.  However, if you have to provide one explicitly, they
                    203: follow the following format:
                    204: 
                    205:     Content-Type: application/X-atf-atffile; version="1"
                    206: 
                    207:     prop: test-suite = NetBSD
                    208: 
                    209:     tp: first_test
                    210:     tp: second_test
                    211:     tp-glob: optional_*_test
                    212:     tp: subdir1
                    213:     tp: subdir2
                    214: 
1.5       jmmv      215: # C test programs
1.1       jmmv      216: 
1.5       jmmv      217: ## Template
1.1       jmmv      218: 
1.2       jmmv      219: The following code snippet provides a C test program with two test cases:
                    220: 
1.1       jmmv      221:     #include <atf-c.h>
                    222: 
                    223:     ATF_TC(tc, my_test_case);
                    224:     ATF_TC_HEAD(tc, my_test_case)
                    225:     {
                    226:         atf_tc_set_md_var(tc, "descr", "This test case ensures that...");
                    227:     }
                    228:     ATF_TC_BODY(tc, my_test_case)
                    229:     {
                    230:         ATF_CHECK(returns_a_boolean()); /* Non-fatal test. */
                    231:         ATF_REQUIRE(returns_a_boolean()); /* Non-fatal test. */
                    232: 
                    233:         ATF_CHECK_EQ(4, 2 + 2); /* Non-fatal test. */
                    234:         ATF_REQUIRE_EQ(4, 2 + 2); /* Fatal test. */
                    235: 
                    236:         if (!condition)
                    237:             atf_tc_fail("Condition not met!"); /* Explicit failure. */
                    238:     }
                    239: 
1.2       jmmv      240:     ATF_TC_WITHOUT_HEAD(tc, another_test_case);
                    241:     ATF_TC_BODY(tc, another_test_case)
                    242:     {
                    243:         /* Do more tests here... */
                    244:     }
                    245: 
1.1       jmmv      246:     ATF_TP_ADD_TCS(tp)
                    247:     {
                    248:         ATF_TP_ADD_TC(tp, my_test_case);
1.2       jmmv      249:         ATF_TP_ADD_TC(tp, another_test_case);
1.1       jmmv      250:     }
                    251: 
1.2       jmmv      252: This program needs to be linked against libatf-c as described below.  Once
                    253: linked, the program automatically gains a main() method that provides a
                    254: consistent user interface to all test programs.  You are simply not inteded to
                    255: provide your own main method, nor to deal with the command-line of the
                    256: invocation.
                    257: 
1.5       jmmv      258: ## How to build
1.1       jmmv      259: 
                    260: To build a C test program, append the name of the test program (without the .c
                    261: extension) to the TESTS_C variable in the Makefile.
                    262: 
                    263: For example:
                    264: 
                    265:     .include <bsd.own.mk>
                    266: 
                    267:     TESTSDIR= ${TESTSBASE}/bin/ls
                    268: 
                    269:     TESTS_C+= fs_test ui_test
                    270: 
                    271:     .include <bsd.test.mk>
                    272: 
1.5       jmmv      273: ## Common functions
1.3       jmmv      274: 
                    275: The following functions are commonly used from within a test case body:
                    276: 
                    277: * ATF_CHECK(boolean_expression): Checks if the given boolean expression is true
                    278:   and, if not, records a failure for the test case but *execution continues*.
                    279:   Using ATF_REQUIRE aborts execution immediately after a failure.
                    280: 
                    281: * ATF_CHECK_EQ(expected_expression, actual_expression): Checks if the two
                    282:   expressions match and, if not, records a failure.  Similarly, ATF_REQUIRE_EQ
                    283:   aborts immediately if the check fails.
                    284: 
                    285: * ATF_CHECK_STREQ(expected_string, actual_string): Same as ATF_CHECK_EQ but
                    286:   performs string comparisons with strcmp.
                    287: 
                    288: * atf_tc_skip(const char *format, ...): Marks the test case as skipped with the
                    289:   provided reason and exits.
                    290: 
                    291: * atf_tc_fail(const char *format, ...): Marks the test case as failed with the
                    292:   provided reason and exits.
                    293: 
                    294: * atf_tc_pass(void): Explicitly marks the test case as passed.  This is
                    295:   *implied* when the test case function ends, so you should not use this in
                    296:   general.
                    297: 
                    298: * atf_expect_fail(const char *format, ...): Tells the atf runtime that the code
                    299:   following this call is expected to raise one or more failures (be it with
                    300:   atf_tc_fail, ATF_CHECK_*, etc.).  Use this to mark a block of code that is
                    301:   known to be broken (e.g. a test that reproduces a known bug).  Use the string
                    302:   parameter to provide an explanation about why the code is broken; if possible,
                    303:   provide a PR number.  Lastly, to terminate the "expected failure" code block
                    304:   and reset the runtime to the default functionality, use the atf_expect_pass()
                    305:   function.
                    306: 
                    307: * atf_expect_death(const char *format, ...): Same as atf_expect_fail but expects
                    308:   an abrupt termination of the test case, be it due to a call to exit() or to
                    309:   the reception of a signal.
                    310: 
                    311: * atf_expect_exit(int exitcode, const char *fomat, ...): Same as atf_expect_fail
                    312:   but expects the test case to exit with a specific exitcode.  Provide -1 to
                    313:   indicate any exit code.
                    314: 
                    315: * atf_expect_signal(int signo, const char *fomat, ...): Same as atf_expect_fail
                    316:   but expects the test case to receive a specific signal.  Provide -1 to
                    317:   indicate any signal.
                    318: 
                    319: * atf_expect_timeout(const char *reason, ...): Same as atf_expect_fail but
                    320:   expects the test case to get stuck and time out.
                    321: 
1.5       jmmv      322: # Shell test programs
1.1       jmmv      323: 
1.5       jmmv      324: ## Template
1.1       jmmv      325: 
1.2       jmmv      326: The following code snippet provides a shell test program with two test cases:
                    327: 
1.1       jmmv      328:     atf_test_case my_test_case
                    329:     my_test_case_head() {
                    330:         atf_set "descr" "This test case ensures that..."
                    331:     }
                    332:     my_test_case_body() {
                    333:         touch file1 file2
                    334: 
                    335:         cat >expout <<EOF
                    336:     file1
                    337:     file2
                    338:     EOF
                    339:         atf_check -s eq:0 -o file:expout -e empty 'ls'
                    340: 
                    341:         atf_check_equal 4 $((2 + 2))
                    342: 
                    343:         if [ 'a' != 'b' ]; then
                    344:             atf_fail "Condition not met!"  # Explicit failure.
                    345:         fi
                    346:     }
                    347: 
1.2       jmmv      348:     atf_test_case another_test_case
                    349:     another_test_case_body() {
                    350:         # Do more tests...
                    351:     }
                    352: 
1.1       jmmv      353:     atf_init_test_cases() {
                    354:         atf_add_test_case my_test_case
1.2       jmmv      355:         atf_add_test_case another_test_case
1.1       jmmv      356:     }
                    357: 
1.2       jmmv      358: This program needs to be be executed with the atf-sh(1) interpreter as described
                    359: below.  The program automatically gains an entry point that provides a
                    360: consistent user interface to all test programs.  You are simply not inteded to
                    361: provide your own "main method", nor to deal with the command-line of the
                    362: invocation.
                    363: 
1.5       jmmv      364: ## How to build
1.1       jmmv      365: 
                    366: To build a shell test program, append the name of the test program (without the
                    367: .sh extension) to the TESTS_SH variable in the Makefile.
                    368: 
                    369: For example:
                    370: 
                    371:     .include <bsd.own.mk>
                    372: 
                    373:     TESTSDIR= ${TESTSBASE}/bin/ls
                    374: 
                    375:     TESTS_SH+= integration_test something_else_test
                    376: 
                    377:     .include <bsd.test.mk>
                    378: 
                    379: If you want to run the test program yourself, you should know that shell-based
                    380: test programs are processed with the atf-sh interpreter.  atf-sh is just a thin
                    381: wrapper over /bin/sh that loads the shared atf code and then delegates execution
                    382: to your source file.
                    383: 
1.5       jmmv      384: ## Common functions
1.3       jmmv      385: 
                    386: The following functions are commonly used from within a test case body:
                    387: 
                    388: * atf_check: This is probably the most useful function for shell-based tests.
                    389:   It may need some experience to get it right, but it allows, in one line, to
                    390:   check the execution of a command.  Where check means: validate exit code,
                    391:   stdout and stderr.  This is just a wrapper over atf-check, so please refer to
                    392:   [atf-check(1)](http://netbsd.gw.com/cgi-bin/man-cgi?atf-check++NetBSD-current)
                    393:   for more details.
                    394: 
                    395: * atf_check_equal value1 value2: Check that the two values are equal and, if
                    396:   not, abort execution.
                    397: 
                    398: * atf_expect_*: Same as their C counterparts; see above.
                    399: 
                    400: * atf_fail reason: Explicitly marks the test case as failed and aborts it.
                    401: 
                    402: * atf_skip reason: Explicitly marks the test case as skipped and exits.
                    403: 
                    404: * atf_pass: Explicitly markts the test case as passed and exits.
                    405: 
                    406: * atf_get_srcdir: Prints the path to the directory where the test case lives.
                    407:   Use as $(atf_get_srcdir)/my-static-data-file.
                    408: 
1.5       jmmv      409: # FAQ
1.1       jmmv      410: 
1.5       jmmv      411: ## How do I atfify a plain test program?
1.1       jmmv      412: 
                    413: Let's suppose you have a program to exercise a particular piece of code.
                    414: Conceptually this implements a test but it does not use atf at all.  For
                    415: example:
                    416: 
                    417:     #include <err.h>
                    418:     #include <stdio.h>
                    419:     #include <stdlib.h>
                    420:     #include <string.h>
                    421: 
                    422:     /* This test program exercises the snprintf function. */
                    423: 
                    424:     int main(void)
                    425:     {
                    426:         char buf[1024];
                    427: 
                    428:         printf("Testing integers");
                    429:         snprintf(buf, sizeof(buf), "%d", 3);
                    430:         if (strcmp(buf, "3") != 0)
                    431:             errx(EXIT_FAILURE, "%d failed");
                    432:         snprintf(buf, sizeof(buf), "a %d b", 5);
                    433:         if (strcmp(buf, "a 5 b") != 0)
                    434:             errx(EXIT_FAILURE, "%d failed");
                    435: 
                    436:         printf("Testing strings");
                    437:         snprintf(buf, sizeof(buf), "%s", "foo");
                    438:         if (strcmp(buf, "foo") != 0)
                    439:             errx(EXIT_FAILURE, "%s failed");
                    440:         snprintf(buf, sizeof(buf), "a %s b", "bar");
                    441:         if (strcmp(buf, "a bar b") != 0)
                    442:             errx(EXIT_FAILURE, "%s failed");
                    443: 
                    444:         return EXIT_SUCCESS;
                    445:     }
                    446: 
                    447: To convert this program into an atf test program, use the template above and
                    448: keep this in mind:
                    449: 
                    450: * Split the whole main function into separate test cases.  In this scenario, the
                    451:   calls to printf(3) delimit a good granularity for the test cases: one for the
                    452:   integer formatter, one for the string formatter, etc.
                    453: 
                    454: * Use the ATF_CHECK* and/or atf_tc_fail functions to do the comparisons and
                    455:   report errors.  errx should not be used.
                    456: 
                    457: The result would look like:
                    458: 
                    459:     #include <atf-c.h>
                    460:     #include <stdio.h>
                    461: 
                    462:     ATF_TC(tc, integer_formatter);
                    463:     ATF_TC_HEAD(tc, integer_formatter)
                    464:     {
                    465:         atf_tc_set_md_var(tc, "descr", "Validates the %d formatter");
                    466:     }
                    467:     ATF_TC_BODY(tc, integer_formatter)
                    468:     {
                    469:         char buf[1024];
                    470: 
                    471:         snprintf(buf, sizeof(1024), "%d", 3);
                    472:         ATF_CHECK_STREQ("3", buf);
                    473: 
                    474:         snprintf(buf, sizeof(1024), "a %d b", 5);
                    475:         ATF_CHECK_STREQ("a 5 b", buf);
                    476:     }
                    477: 
                    478:     ATF_TC(tc, string_formatter);
                    479:     ATF_TC_HEAD(tc, string_formatter)
                    480:     {
                    481:         atf_tc_set_md_var(tc, "descr", "Validates the %s formatter");
                    482:     }
                    483:     ATF_TC_BODY(tc, string_formatter)
                    484:     {
                    485:         char buf[1024];
                    486: 
                    487:         snprintf(buf, sizeof(1024), "%s", "foo");
                    488:         ATF_CHECK_STREQ("foo", buf);
                    489: 
                    490:         snprintf(buf, sizeof(1024), "a %s b", "bar");
                    491:         ATF_CHECK_STREQ("a bar b", buf);
                    492:     }
                    493: 
                    494:     ATF_TP_ADD_TCS(tp)
                    495:     {
                    496:         ATF_TP_ADD_TC(tp, integer_formatter);
                    497:         ATF_TP_ADD_TC(tp, string_formatter);
                    498:     }
                    499: 
                    500: Which can later be invoked as any of:
                    501: 
                    502:     $ ./snprintf_test integer_formatter
                    503:     $ ./snprintf_test string_formatter
                    504:     $ atf-run snprintf_test | atf-report
                    505: 
1.5       jmmv      506: ## How do I write a test case for an unfixed PR?
1.3       jmmv      507: 
                    508: Use the "expectations" mechanism to define part of the test case as faulty,
                    509: crashy, etc.  For example, suppose we have PR 1 that reports a condition in
                    510: which snprintf() does the wrong formatting when using %s, and PR 2 that mentions
                    511: that another snprintf() call using %d with number 5 causes a segfault.  We could
                    512: do:
                    513: 
                    514:     #include <atf-c.h>
                    515:     #include <signal.h>
                    516:     #include <stdio.h>
                    517: 
                    518:     ATF_TC_WITHOUT_HEAD(tc, integer_formatter);
                    519:     ATF_TC_BODY(tc, integer_formatter)
                    520:     {
                    521:         char buf[1024];
                    522: 
                    523:         snprintf(buf, sizeof(buf), "Hello %d\n", 1);
                    524:         ATF_CHECK_STREQ("Hello 1", buf);
                    525: 
                    526:         atf_tc_expect_signal(SIGSEGV, "PR 2: %%d with 5 causes a crash");
                    527:         snprintf(buf, sizeof(buf), "Hello %d\n", 5);
                    528:         atf_tc_expect_pass();
                    529:         ATF_CHECK_STREQ("Hello 5", buf);
                    530:     }
                    531: 
                    532:     ATF_TC_WITHOUT_HEAD(tc, string_formatter);
                    533:     ATF_TC_BODY(tc, string_formatter)
                    534:     {
                    535:         char buf[1024];
                    536: 
                    537:         snprintf(buf, sizeof(buf), "Hello %s\n", "world!");
                    538:         atf_tc_expect_failure("PR 1: %%s does not work");
                    539:         ATF_CHECK_STREQ("Hello world!", buf);
                    540:         atf_tc_expect_pass();
                    541:     }
                    542: 
                    543:     ATF_TP_ADD_TCS(tp)
                    544:     {
                    545:         ATF_TP_ADD_TC(tp, integer_formatter);
                    546:         ATF_TP_ADD_TC(tp, string_formatter);
                    547:     }
                    548: 
1.5       jmmv      549: ## Do I need to remove temporary files?
1.1       jmmv      550: 
                    551: No.  atf-run does this automatically for you, because it runs every test program
                    552: in its own temporary subdirectory.

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb