<commit_before>/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "Charmonizer/Test.h"

static void
S_TestBatch_destroy(chaz_TestBatch *batch);

static void
S_TestBatch_run_test(chaz_TestBatch *batch);

#define CHAZ_TEST_PRINT_MESS(_pattern, _args) \
    va_start(_args, _pattern); \
    vprintf(_pattern, _args); \
    va_end(_args); \
    printf("\n");

void
chaz_Test_init(void) {
    /* Unbuffer stdout. */
    int check_val = setvbuf(stdout, NULL, _IONBF, 0);
    if (check_val != 0) {
        fprintf(stderr, "Failed when trying to unbuffer stdout\n");
    }
}

chaz_TestBatch*
chaz_Test_new_batch(const char *batch_name, unsigned num_tests,
                    chaz_TestBatch_test_func_t test_func) {
    chaz_TestBatch *batch = (chaz_TestBatch*)malloc(sizeof(chaz_TestBatch));

    /* Assign. */
    batch->num_tests       = num_tests;
    batch->name            = strdup(batch_name);
    batch->test_func       = test_func;
<commit_msg>Handle malloc failures by the book.  Use strlen/malloc/strcpy instead of strdup, since strdup isn't C89.<commit_after>/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "Charmonizer/Test.h"

static void
S_TestBatch_destroy(chaz_TestBatch *batch);

static void
S_TestBatch_run_test(chaz_TestBatch *batch);

#define CHAZ_TEST_PRINT_MESS(_pattern, _args) \
    va_start(_args, _pattern); \
    vprintf(_pattern, _args); \
    va_end(_args); \
    printf("\n");

void
chaz_Test_init(void) {
    /* Unbuffer stdout. */
    int check_val = setvbuf(stdout, NULL, _IONBF, 0);
    if (check_val != 0) {
        fprintf(stderr, "Failed when trying to unbuffer stdout\n");
    }
}

chaz_TestBatch*
chaz_Test_new_batch(const char *batch_name, unsigned num_tests,
                    chaz_TestBatch_test_func_t test_func) {
    chaz_TestBatch *batch = (chaz_TestBatch*)malloc(sizeof(chaz_TestBatch));
    if (!batch) {
        fprintf(stderr, "Out of memory\n");
        return NULL;
    }
    batch_name = batch_name ? batch_name : "";

    /* Assign. */
    batch->num_tests       = num_tests;
    batch->test_func       = test_func;
    batch->name            = (char*)malloc(strlen(batch_name) + 1);
    if (!batch->name) {
        fprintf(stderr, "Out of memory\n");
        return NULL;
    }
    strcpy(batch->name, batch_name);

{'fraction_non_alphanumeric': 0.09791983764586504, 'fraction_numerical': 0.00380517503805175, 'mean_word_length': 3.5478662053056516, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1965730', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1190, 'n_words': 392}