ATF_TC_BODY(exec_cleanup, tc) { atf_fs_path_t out, err; atf_check_result_t result; bool exists; do_exec(tc, "exit-success", &result); RE(atf_fs_path_init_fmt(&out, "%s", atf_check_result_stdout(&result))); RE(atf_fs_path_init_fmt(&err, "%s", atf_check_result_stderr(&result))); RE(atf_fs_exists(&out, &exists)); ATF_CHECK(exists); RE(atf_fs_exists(&err, &exists)); ATF_CHECK(exists); atf_check_result_fini(&result); RE(atf_fs_exists(&out, &exists)); ATF_CHECK(!exists); RE(atf_fs_exists(&err, &exists)); ATF_CHECK(!exists); atf_fs_path_fini(&err); atf_fs_path_fini(&out); }
ATF_TC_BODY(exists, tc) { atf_error_t err; atf_fs_path_t pdir, pfile; bool b; RE(atf_fs_path_init_fmt(&pdir, "dir")); RE(atf_fs_path_init_fmt(&pfile, "dir/file")); create_dir(atf_fs_path_cstring(&pdir), 0755); create_file(atf_fs_path_cstring(&pfile), 0644); printf("Checking existence of a directory\n"); RE(atf_fs_exists(&pdir, &b)); ATF_REQUIRE(b); printf("Checking existence of a file\n"); RE(atf_fs_exists(&pfile, &b)); ATF_REQUIRE(b); /* XXX: This should probably be a separate test case to let the user * be aware that some tests were skipped because privileges were not * correct. */ if (!atf_user_is_root()) { printf("Checking existence of a file inside a directory without " "permissions\n"); ATF_REQUIRE(chmod(atf_fs_path_cstring(&pdir), 0000) != -1); err = atf_fs_exists(&pfile, &b); ATF_REQUIRE(atf_is_error(err)); ATF_REQUIRE(atf_error_is(err, "libc")); ATF_REQUIRE(chmod(atf_fs_path_cstring(&pdir), 0755) != -1); atf_error_free(err); } printf("Checking existence of a non-existent file\n"); ATF_REQUIRE(unlink(atf_fs_path_cstring(&pfile)) != -1); RE(atf_fs_exists(&pfile, &b)); ATF_REQUIRE(!b); atf_fs_path_fini(&pfile); atf_fs_path_fini(&pdir); }
ATF_TC_BODY(srcdir_exists, tc) { atf_fs_path_t p; bool b; RE(atf_fs_path_init_fmt(&p, "%s/datafile", atf_tc_get_config_var(tc, "srcdir"))); RE(atf_fs_exists(&p, &b)); atf_fs_path_fini(&p); if (!b) atf_tc_fail("Cannot find datafile"); }
static bool exists(const char *p) { bool b; atf_fs_path_t pp; RE(atf_fs_path_init_fmt(&pp, "%s", p)); RE(atf_fs_exists(&pp, &b)); atf_fs_path_fini(&pp); return b; }
static atf_error_t handle_srcdir(struct params *p) { atf_error_t err; atf_dynstr_t leafname; atf_fs_path_t exe, srcdir; bool b; err = atf_fs_path_copy(&srcdir, &p->m_srcdir); if (atf_is_error(err)) goto out; if (!atf_fs_path_is_absolute(&srcdir)) { atf_fs_path_t srcdirabs; err = atf_fs_path_to_absolute(&srcdir, &srcdirabs); if (atf_is_error(err)) goto out_srcdir; atf_fs_path_fini(&srcdir); srcdir = srcdirabs; } err = atf_fs_path_leaf_name(&srcdir, &leafname); if (atf_is_error(err)) goto out_srcdir; else { const bool libs = atf_equal_dynstr_cstring(&leafname, ".libs"); atf_dynstr_fini(&leafname); if (libs) { err = srcdir_strip_libtool(&srcdir); if (atf_is_error(err)) goto out; } } err = atf_fs_path_copy(&exe, &srcdir); if (atf_is_error(err)) goto out_srcdir; err = atf_fs_path_append_fmt(&exe, "%s", progname); if (atf_is_error(err)) goto out_exe; err = atf_fs_exists(&exe, &b); if (!atf_is_error(err)) { if (b) { err = atf_map_insert(&p->m_config, "srcdir", strdup(atf_fs_path_cstring(&srcdir)), true); } else { err = user_error("Cannot find the test program in the source " "directory `%s'", atf_fs_path_cstring(&srcdir)); } } out_exe: atf_fs_path_fini(&exe); out_srcdir: atf_fs_path_fini(&srcdir); out: return err; }