testarray.inc

ldmud-3.3.719/test/inc/testarray.inc · 1.4 KB

From the archive ldmud-3.3.719.tar.gz

Download the archive   « Back to the archive contents

// Indices into the array of a test.
#define TI_NAME          0       // The name of the test
#define TI_FLAGS         1       // Some Flags
#define TI_CLOSURE       2       // The function to be evaluated

// Flags
#define TF_ERROR          1       // The function should generate an error.
#define TF_DONTCHECKERROR 2       // Doesn't matter if error or not, as long as it does not crash.

void run_array(mixed* testarray, closure callback)
{
    int errors;
    
    // If there's an error:
    call_out(callback, 0, 1);
    
    foreach(mixed test: testarray)
    {
        msg("Running Test %s...", test[TI_NAME]);

        if(test[TI_FLAGS]&TF_ERROR)
        {
            if(!catch(funcall(test[TI_CLOSURE]);nolog))
            {
                errors++;
                msg(" FAILURE! (There was no error.)\n");
            }
            else
                msg(" Success.\n");
        }
        else if (test[TI_FLAGS]&TF_DONTCHECKERROR)
        {
            catch(funcall(test[TI_CLOSURE]);nolog);
            // if we surived the test: great
            msg(" Success.\n");
        }
        else
        {
            if(funcall(test[TI_CLOSURE]))
                msg(" Success.\n");
            else
            {
                errors++;
                msg(" FAILURE! (Wrong result.)\n");
            }
        }
    }
    
    remove_call_out(callback);

    funcall(callback, errors && 1);
}

Site Stats

Snippets: 1791
Codebases: 571