Skip to content

Proposal: stating point of a testing library #172

@seymourpoler

Description

@seymourpoler

First of all many thanks, for all you effort. I think that this language has a great future. To me this programming language is very interesting.
I've noticed that there is no testing library (I could be wrong). Nowadays most of the modern languages have one (or more than one), for example go, zig, rust, ...

This proposal is heavily inspired in jasmine and the javascript testing ecosystem.
It looks lke this:

import fmt;

fn main():void {  
    describe("when summatory is requested", fn() {
        it("should add two numbers correctly", fn() {
            const sumExpected = 5;
            
            var sum = add(2, 3);

            expect(sum, sumExpected);
        });
    });
}

fn describe(string name, fn():void function): void {
    fmt.printf("Running test: %s\n", name);
    function();
}

fn it(string name,   fn():void function): void {
    fmt.printf(" - %s\n", name);
    function();
}

fn expect<T, U>(T actual, U expected): void {
    if(actual == expected) {
        fmt.printf("   ✔ Test passed\n");
    } else {
        fmt.printf("   ✘ Test failed: expected %v but got %v\n", expected, actual);
    }
}

fn add(int a, int b): int {
    return a + b;
}

the outcome of the test above

Running test: when summatory is requested
 - should add two numbers correctly
   ✔ Test passed

It is only a starting point and a proposal for a testing library.

Many thanks!!!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions