One icon indicating copy to clipboard operation
One copied to clipboard

🧪 Testing 🧪

Open javatlacati opened this issue 4 years ago • 12 comments

How can you test the code?

javatlacati avatar May 25 '21 18:05 javatlacati

We have some tests that run on pull request.

We plan to add more. We also use pre-commit.

jbampton avatar May 25 '21 18:05 jbampton

Yes, but.. if I write

main {
   ret 0
}

how do I test it without converting it to another language? Do you have any One-Language-based testing framework?

perhaps to do something like:

assertToBe(main, 0,"expected return value to be 0")

javatlacati avatar May 25 '21 18:05 javatlacati

Codewars training hey ?

You will have to ask @BaseMax what he thinks

jbampton avatar May 25 '21 18:05 jbampton

Actually having a testing framework is all you pre-require to get it included inside Codewars, for your consideration

javatlacati avatar May 25 '21 18:05 javatlacati

Hi Ruslan;

We are happy you to join our team and be with us. It will be great if you accept our invite to join this org even if you do not have the opportunity to work, you can advise us.

perhaps to do something like: assertToBe(main, 0,"expected return value to be 0")

It was a very good offer.

Best;

BaseMax avatar May 27 '21 22:05 BaseMax

Dear ismael suggest a c library for unit testing.

https://github.com/ThrowTheSwitch/Unity cc https://github.com/One-Language/One/issues/55

BaseMax avatar May 27 '21 22:05 BaseMax

Hello friends, if we agree with using this framework I have a few points to discuss: 1- https://github.com/ThrowTheSwitch/Unity/blob/master/docs/UnityGettingStartedGuide.md here is a good place to start learning about it. 2- @BaseMax does using unity require any changes on the code structure? 3- what do you think guys from this attempt to use unity? 4- In terms of what should we test first; I think that we can start by: ast, compile, error, file, lexer, parser, token. Then we can continue our tests on the remaining files of the project.

abdorah avatar Jun 05 '21 22:06 abdorah

Thank you Kotbi. @abdorah Yeah, auto testing (unit-test, ...) is necessary for this project.

http://www.throwtheswitch.org/unity

Yes, it's a good library, which I have no problem with.

These are the files that I think need to be tested:

  • lexer.test.c
  • parser.test.c
  • ast.test.c

In the lexical stage we will have a series of test texts that we have to have in front of a presentation of tokens. (token types array) And check if the tokens we get from the program are equal to the tokens we expect.

BaseMax avatar Jun 06 '21 00:06 BaseMax

Now I see your fork. It's good, you moved the test file to another directory. :+1:

arg-test is also a good idea. You can pass fake argc,argv parameters and compare results.

If you have done this. please send your PR. It's welcome. @abdorah Thanks

BaseMax avatar Jun 06 '21 00:06 BaseMax

Thank you @BaseMax ! I took into consideration the files that you said that they need tests. I started with lexer.test.c . Also, I omitted the file arg-test because I think that we can leave it to the end (We can use it to make something similar to an integration test, what do you think?). This is what I did so far: https://github.com/abdorah/One/blob/master/unit-tests/ It is basically something like this:

#include "unity.h"
#include "error.h"
#include "lexer.h"

char *filename;
char *input;
ErrorsContainer *errors;
Lexer *lex;

void setUp(void)
{
    //This is the initialization for the variables needed for the unit testing.
    filename = "tests/1-hello-world.et";
    input = "";
    ErrorsInit(errors);
	lex = lexerInit(filename, input, errors);
}

void tearDown(void)
{
	lexerFree(lex);
}

void test_function_should_check_lex(void)
{
	TEST_ASSERT_EQUAL_INT(EXIT_SUCCESS, lexerCheck(lex, errors));
}

int main(void)
{
	UNITY_BEGIN();
	RUN_TEST(test_function_should_check_lex);
	return UNITY_END();
}

This can be improved (especially the variables I used). Thank you for your review.

abdorah avatar Jun 06 '21 02:06 abdorah

Thank you. Send your PR when it's ready.

On Sun, Jun 6, 2021, 6:31 AM Kotbi Abderrahmane @.***> wrote:

Thank you @BaseMax https://github.com/BaseMax ! I took into consideration the files that you said that they need tests. I started with lexer.test.c . Also, I omitted the file arg-test because I think that we can leave it to the end (We can use it to make something similar to an integration test, what do you think?). This is what I did so far: https://github.com/abdorah/One/blob/master/unit-tests/ It is basically something like this:

#include "unity.h" #include "error.h" #include "lexer.h" char *filename;char *input; ErrorsContainer *errors; Lexer *lex; void setUp(void) { //This is the initialization for the variables needed for the unit testing. filename = "tests/1-hello-world.et"; input = ""; ErrorsInit(errors); lex = lexerInit(filename, input, errors); } void tearDown(void) { lexerFree(lex); } void test_function_should_check_lex(void) { TEST_ASSERT_EQUAL_INT(EXIT_SUCCESS, lexerCheck(lex, errors)); } int main(void) { UNITY_BEGIN(); RUN_TEST(test_function_should_check_lex); return UNITY_END(); }

This can be improved (especially the variables I used). Thank you for your review.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/One-Language/One/issues/36#issuecomment-855323811, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUI56DRFCZFVEME24DWFPDTRLJHLANCNFSM45P4WMNQ .

BaseMax avatar Jun 06 '21 09:06 BaseMax