Beispiel #1
0
/// Executes the cleanup of a test case.
///
/// \param test_program Path to the test program to execute.
/// \param test_case Name of the test case to run.
/// \param user_variables Set of configuration variables to pass to the test.
static void
exec_cleanup(const char* test_program, const char* test_case,
             const char* const user_variables[])
{
    char* name;
    kyua_error_t error = kyua_text_printf(&name, "%s:cleanup", test_case);
    if (kyua_error_is_set(error))
        kyua_error_err(EXIT_FAILURE, error,
                       "Failed to construct argument list");

    const size_t nargs =
        1 /* test_program */ +
        + 2 * count_variables(user_variables) /* -v name=value */
        + 1 /* test_case */ +
        1 /* NULL */;

    const char** args = malloc(sizeof(const char*) * nargs);
    if (args == NULL)
        kyua_error_err(EXIT_FAILURE, kyua_oom_error_new(),
                       "Failed to construct arguments list");

    size_t i = 0;
    args[i++] = test_program;
    const char* const* iter;
    for (iter = user_variables; *iter != NULL; ++iter) {
        args[i++] = "-v";
        args[i++] = *iter;
    }
    args[i++] = name;
    args[i++] = NULL;
    assert(i == nargs);

    kyua_run_exec(test_program, args);
}
Beispiel #2
0
ATF_TC_BODY(printf__empty, tc)
{
    char* buffer;
    kyua_error_t error = kyua_text_printf(&buffer, "%s", "");
    ATF_REQUIRE(!kyua_error_is_set(error));
    ATF_REQUIRE_STREQ("", buffer);
}
Beispiel #3
0
Datei: env.c Projekt: namore/kyua
/// Sets a collection of configuration variables in the environment.
///
/// \param user_variables Set of configuration variables to pass to the test.
///     This is an array of strings of the form var=value and must have been
///     previously sanity-checked with kyua_env_check_configuration.
///
/// \return An error if there is a problem allocating memory.
///
/// \post The environment contains a new collection of TEST_ENV_* variables that
/// matches the input user_variables.
kyua_error_t
kyua_env_set_configuration(const char* const user_variables[])
{
    const char* const* iter;
    for (iter = user_variables; *iter != NULL; ++iter) {
        kyua_error_t error;

        char* var_value = strdup(*iter);
        if (var_value == NULL)
            return kyua_oom_error_new();

        char* value = strchr(var_value, '=');
        assert(value != NULL);  // Must have been validated.
        *value = '\0';
        value += 1;

        char* var;
        error = kyua_text_printf(&var, "TEST_ENV_%s", var_value);
        if (kyua_error_is_set(error)) {
            free(var_value);
            return error;
        }

        error = kyua_env_set(var, value);
        if (kyua_error_is_set(error)) {
            free(var_value);
            return error;
        }
    }
    return kyua_error_ok();
}
Beispiel #4
0
ATF_TC_BODY(printf__some, tc)
{
    char* buffer;
    kyua_error_t error = kyua_text_printf(&buffer, "this is %d %s", 123, "foo");
    ATF_REQUIRE(!kyua_error_is_set(error));
    ATF_REQUIRE_STREQ("this is 123 foo", buffer);
    free(buffer);
}