Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test framework and testing solution for cito #44

Open
danon opened this issue Nov 4, 2021 · 10 comments
Open

Test framework and testing solution for cito #44

danon opened this issue Nov 4, 2021 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@danon
Copy link

danon commented Nov 4, 2021

Hi! I love your idea for a language specifically designed to be transpiled to other languages! I myself code with multiple langauges and always missed the option like this.

However, I find it stupidly absent that there's no solution for testing your application in Ć so far, for me, I could start using it right now, but I use TDD for 8 years now, and that's a big deal braker for me.

I find it necessary for two reasons.

  • First, I would like to code just in Ć, and write tests for my code in Ć, just for the sake of them - this is a must have IMO.
  • Second of all, when you transpile Ć language to Java/PHP, you could also transpile tests from ĆTest to jUnit or phpUnit. This is open for discussion, since the choosing of testing library can be subjective (for example for python unittest vs pytest will be hard to choose).

I could help you develop such a solution or code it, since I know all the supported languages (c#, java, php, python and c).

@pfusik pfusik self-assigned this Nov 4, 2021
@pfusik
Copy link
Collaborator

pfusik commented Nov 4, 2021

Thank you! I like your idea.

I have experience with:

  • C++ GoogleTest
  • C# NUnit
  • D builtin unittest
  • Perl Test modules

I'd appreciate your help in designing a unit testing framework. Please start.

One problem would be selecting one of the competing frameworks for every target language. Perhaps we could support many per language?

Also, there's no PHP backend yet. Adding one is also a good idea.

@danon
Copy link
Author

danon commented Nov 4, 2021

One problem would be selecting one of the competing frameworks for every target language. Perhaps we could support many per language?

Is this an option? If it is, great. However it comes with other difficulties, for example jUnit4 vs jUnit5 have different APIs, for example regarding exceptions,so does PhpUnit7 vs PhpUnit8.

I assume the biggest priority is that tests written in Ć, must be transpiled to all supported languages and run in those as well.

I'll start working on the idea today night, and I'll present my idea in the morning, is that all right? :)

@danon
Copy link
Author

danon commented Nov 4, 2021

PS: @pfusik How do you decide what language version to transpile to? For example you always transpile Java to Java8? Or how do you choose that?

@pfusik
Copy link
Collaborator

pfusik commented Nov 4, 2021

cito could have a new option, such as --target-test-framework.

It used to have options for language versions: C89 vs C99, Perl 5.8 vs 5.10, old-style JavaScript vs JavaScript with typed arrays. These haven't aged well: MSVC supports C99 since 2013, no-one uses Perl 5.8 and even IE supports typed arrays now, I think. Current strategy is to support the latest versions available: C++20 (which has no full compiler yet), .NET 5, etc.

@danon
Copy link
Author

danon commented Nov 4, 2021

So I understand C, C++, JS and Java are your primary concern and you will support Java, Scala and Python as a secondary concern? Or are all of them equally important?

And my second question, is there a way to run just Ć, without transpiling it to anything?

Or maybe to implicitly transpile it to something that always work like cito run file.ci?

And BTW, I think you should support Go in ć, i think this could be a really Big selling Point of your langauge.

@pfusik
Copy link
Collaborator

pfusik commented Nov 5, 2021

Java isn't "more important" than Python. What made you think so? Both are popular languages and I want cito to handle both well. There is no Scala support, but I think you can use Java code from Scala.

There's no way to run Ć natively. I imagine that tests would be transpiled same way as any other Ć code, then compiled and run using existing target-specific tools.

Since cito is currently implemented in C#, you can rely on users having .NET SDK installed. That means it would be nice to run tests on .NET without extra dependencies such as JDK.

As for Go, please file another ticket.

@danon
Copy link
Author

danon commented Nov 10, 2021

@pfusik I've got some ideas and solutions for the tests in Ć.

Is there a place where we can share ideas? Perhaps gitter would be good.

@pfusik
Copy link
Collaborator

pfusik commented Nov 10, 2021

I don't know about gitter, but there's a Discussions tab here on GitHub that I recently enabled.

@danon
Copy link
Author

danon commented Nov 10, 2021

@pfusik Gitter is like slack dedicated for special repositories. There's gitter for ruby on rails, gitter for django, gitter for angular, etc.

But I think discussions are fine too :)

@pfusik pfusik added the enhancement New feature or request label Aug 13, 2023
@caesay
Copy link
Contributor

caesay commented Feb 21, 2024

I think building a very simple test framework into fusion (rather than relying on the testing frameworks in each target language) is the move here.

We can be inspired by rust tests, which allows you to very simply declare tests in the same source files, for example:

fn add(n: u32, y: u32) -> u32 {
    return n + y;
}

#[test]
fn it_works() {
    let result = add(2, 2);
    assert!(result == 4);
}

The only thing that denotes the later function a test is the #[test] attribute. When compiling regular code, we simply strip out these test methods.

Since fusion doesn't support top level functions (neither to some of our target languages) our tests could be in dedicated classes:

class Tests 
{
    #[test]
    public void TestUtilSomething()
    {
        assert Util.Something() == true;
    }
}

Or they could even be directly in the logic classes themselves:

class Adder
{
    public int Add(int x, int y)
    {
        return x + y;
    }

    #[test]
    public void TestAdd()
    {
        assert Add(2, 2) == 4;
    }
}

This capability would allow us to test private functions, and since fusion requires a parameterless constructor we will not have any issues creating an instance of the class to run the test.

We would need to write a new --test argument or separate command into fut.exe, which does a special compile, including all the test functions, and plus a simple test runner which just executes each test sequentially. A test passes if it doesn't fail an assert. Since fut already supports asserts, this architecture fits nicely.

The hardest part would probably be actually running all the tests, because fut would need to know about various native language compilers/interpreters. Perhaps for the first version we can skip this and leave running the tests up to the developer.

@danon danon changed the title Test framework nad testing solution for cito Test framework and testing solution for cito Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants