Пример #1
0
void test_snippet(std::string const& source)
{
    Branch branch;
    branch.compile(source);

    if (test_fail_on_static_error(&branch))
        return;

    Stack context;
    evaluate_branch(&context, &branch);

    if (test_fail_on_runtime_error(context))
        return;

    // Try stripping orphaned state, this should not have an effect.
    caValue trash;
    strip_orphaned_state(&branch, &context.state, &trash);

    if (!is_null(&trash)) {
        std::cout << "Falsely orphaned state in " << get_current_test_name() << std::endl;
        std::cout << "Code = " << source << std::endl;
        std::cout << "Trash = " << trash.toString() << std::endl;
        declare_current_test_failed();
        return;
    }
}
Пример #2
0
void test_trimmed_state(std::string const& source, std::string const& dest,
    std::string const& expectedTrash)
{
    Branch sourceBranch;
    sourceBranch.compile(source);

    if (test_fail_on_static_error(&sourceBranch))
        return;

    Stack context;
    evaluate_branch(&context, &sourceBranch);

    if (test_fail_on_runtime_error(context))
        return;

    Branch destBranch;
    destBranch.compile(dest);

    if (test_fail_on_static_error(&destBranch))
        return;

    caValue trash;
    strip_orphaned_state(&destBranch, &context.state, &trash);

    if (expectedTrash != trash.toString()) {
        declare_current_test_failed();
        std::cout << "In test " << get_current_test_name() << std::endl;
        std::cout << expectedTrash << " != " << trash.toString() << std::endl;
    }
}
Пример #3
0
bool test_fail_on_static_error(Block* block)
{
    if (has_static_errors(block)) {
        std::cout << "Static error in " << get_current_test_name() << std::endl;
        print_static_errors_formatted(block, std::cout);
        std::cout << std::endl;
        declare_current_test_failed();
        return true;
    }
    return false;
}
Пример #4
0
bool test_fail_on_runtime_error(Stack& context)
{
    if (context.errorOccurred) {
        std::cout << "Runtime error in " << get_current_test_name() << std::endl;
        print_error_stack(&context, std::cout);
        std::cout << std::endl;
        declare_current_test_failed();
        return true;
    }
    return false;
}
Пример #5
0
bool test_fail_on_runtime_error(VM* vm)
{
    if (vm_has_error(vm)) {
        std::cout << "Runtime error in " << get_current_test_name() << std::endl;
        //circa_dump_stack_trace(&context);
        std::cout << std::endl;
        declare_current_test_failed();
        return true;
    }
    return false;
}