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

🧪 Testing 🧪 #36

Open
javatlacati opened this issue May 25, 2021 · 12 comments
Open

🧪 Testing 🧪 #36

javatlacati opened this issue May 25, 2021 · 12 comments
Labels
documentation Enhancement New feature or request hacktoberfest Help Wanted Extra attention is needed Question Further information is requested tests

Comments

@javatlacati
Copy link

How can you test the code?

@jbampton
Copy link
Member

We have some tests that run on pull request.

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

@jbampton jbampton added the Question Further information is requested label May 25, 2021
@javatlacati
Copy link
Author

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")

@jbampton
Copy link
Member

Codewars training hey ?

You will have to ask @BaseMax what he thinks

@javatlacati
Copy link
Author

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

@jbampton jbampton added the tests label May 27, 2021
@BaseMax
Copy link
Member

BaseMax commented May 27, 2021

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
Copy link
Member

BaseMax commented May 27, 2021

Dear ismael suggest a c library for unit testing.

https://github.com/ThrowTheSwitch/Unity
cc #55

@jbampton jbampton added Enhancement New feature or request documentation Help Wanted Extra attention is needed labels Jun 4, 2021
@jbampton jbampton changed the title Testing 🧪 Testing 🧪 Jun 5, 2021
@abdorah
Copy link
Member

abdorah commented Jun 5, 2021

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.

@BaseMax
Copy link
Member

BaseMax commented Jun 6, 2021

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
Copy link
Member

BaseMax commented Jun 6, 2021

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

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

@abdorah
Copy link
Member

abdorah commented Jun 6, 2021

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.

@BaseMax
Copy link
Member

BaseMax commented Jun 6, 2021 via email

@javatlacati javatlacati removed their assignment Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Enhancement New feature or request hacktoberfest Help Wanted Extra attention is needed Question Further information is requested tests
Projects
None yet
Development

No branches or pull requests

12 participants