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

can't understand how to use unittest++ #1580

Closed
zubovm opened this Issue Mar 3, 2017 · 9 comments

Comments

Projects
None yet
3 participants
@zubovm

zubovm commented Mar 3, 2017

If one will follow this description: http://codelite.org/LiteEditor/UnitTestPP he or she will notice three things (version 10.0.0):

  1. no tests were added after clicking OK in Create tests for class Dialog to Test Project's main.cpp
  2. if one will add them manually, Test Project will not compile because it does not know anything about paths to .h files of project to be tested
  3. if you add these paths manually (to the Project Settings or just use "../ProjectName/" in #include, cause it is the same workspace), it will compile but (obviously) will not link. and now one does not know what to do at all - how to add foreign *.o files to linker in unittest++ plugin project.
@eranif

This comment has been minimized.

Show comment
Hide comment
@eranif

eranif Mar 3, 2017

Owner

Thank you for reporting this. I will follow the instructions and will fix what is broken

Owner

eranif commented Mar 3, 2017

Thank you for reporting this. I will follow the instructions and will fix what is broken

@zubovm

This comment has been minimized.

Show comment
Hide comment
@zubovm

zubovm Mar 3, 2017

Thank you very much.

By the way, may be you can tell (if it is not very complicated) simple general way to use classes from the different Projects of the same Workspace ? As far as I can see, there is no conception of 'project dependency' in CodeLite ?

P.S. Also when I try to build Test Project, I get this:
error_msg
(I just ignore it, but may be it is important)

P.P.S. after all I did it: added ClassName.cpp.o to Linker Options (there is no hope to add it to the library list - parser couldn't distinguish .o files from libSomething.a or libSomething.so and will use -l); now it works a bit, but only when I use 'Build and Run' Ctrl-F9 - in that case it runs tests in terminal; but if one will try to just run it, Ctrl-F5, he or she will see nothing. Also there is no such thing as UnitTest++ tab in the Output View now.

Hope that helps !

zubovm commented Mar 3, 2017

Thank you very much.

By the way, may be you can tell (if it is not very complicated) simple general way to use classes from the different Projects of the same Workspace ? As far as I can see, there is no conception of 'project dependency' in CodeLite ?

P.S. Also when I try to build Test Project, I get this:
error_msg
(I just ignore it, but may be it is important)

P.P.S. after all I did it: added ClassName.cpp.o to Linker Options (there is no hope to add it to the library list - parser couldn't distinguish .o files from libSomething.a or libSomething.so and will use -l); now it works a bit, but only when I use 'Build and Run' Ctrl-F9 - in that case it runs tests in terminal; but if one will try to just run it, Ctrl-F5, he or she will see nothing. Also there is no such thing as UnitTest++ tab in the Output View now.

Hope that helps !

@eranif

This comment has been minimized.

Show comment
Hide comment
@eranif

eranif Apr 9, 2017

Owner

This error is indeed important. It means that somewhere in your project settings, there is a reference to an environment variable named UNIT_TEST_PP_SRC_DIR but this variable is not defined.

This will probably will lead to build error

Owner

eranif commented Apr 9, 2017

This error is indeed important. It means that somewhere in your project settings, there is a reference to an environment variable named UNIT_TEST_PP_SRC_DIR but this variable is not defined.

This will probably will lead to build error

@eranif eranif closed this Apr 9, 2017

@zubovm

This comment has been minimized.

Show comment
Hide comment
@zubovm

zubovm Apr 9, 2017

Emm. Sorry, but I didn't understand. Does any workaround was found ? Of course I did not delete that environment variable. Or should I add it by myself ? There is not a word about it at the page with description about unit test creation in CodeLite, I thought that that variable would be created automatically.

zubovm commented Apr 9, 2017

Emm. Sorry, but I didn't understand. Does any workaround was found ? Of course I did not delete that environment variable. Or should I add it by myself ? There is not a word about it at the page with description about unit test creation in CodeLite, I thought that that variable would be created automatically.

@eranif eranif reopened this Apr 9, 2017

@eranif

This comment has been minimized.

Show comment
Hide comment
@eranif

eranif Apr 9, 2017

Owner

Sorry, closed by mistake. Re-opened.
The unit test framework should be installed somewhere in your system and this location should be pointed by the environment variable UNIT_TEST_PP_SRC_DIR. It can not be done automatically, since CodeLite does not know where your UnitTest++ is installed

Owner

eranif commented Apr 9, 2017

Sorry, closed by mistake. Re-opened.
The unit test framework should be installed somewhere in your system and this location should be pointed by the environment variable UNIT_TEST_PP_SRC_DIR. It can not be done automatically, since CodeLite does not know where your UnitTest++ is installed

@eranif

This comment has been minimized.

Show comment
Hide comment
@eranif

eranif Apr 12, 2017

Owner

I have updated the project and removed the environment variables from the project settings.
I have also updated (and tested the UnitTest++ page) : http://codelite.org/LiteEditor/UnitTestPP

Owner

eranif commented Apr 12, 2017

I have updated the project and removed the environment variables from the project settings.
I have also updated (and tested the UnitTest++ page) : http://codelite.org/LiteEditor/UnitTestPP

@eranif eranif closed this Apr 12, 2017

eranif pushed a commit that referenced this issue Apr 12, 2017

@ywrt

This comment has been minimized.

Show comment
Hide comment
@ywrt

ywrt Oct 23, 2017

This doesn't appear to be fixed still. I'm running codelite 11.0, and it still creates blank test files.

Steps:

  1. Added unittest++ project per http://codelite.org/LiteEditor/UnitTestPP
  2. Right-click, select 'unitest++/Create tests for class'.
  3. Untick a couple of functions I don't need tests for, leaving one.
  4. Add 'mapper_test.cpp' as an output function.

Result: I get a 'mapper_test.cpp' file that contains the single line '#include <UnitTest++.h>' and nothing else. No errors are reported, it just doesn't work correctly.

If I manually add a test, it fails because the project doesnt know anything about the paths to the original.

Basically, from the original bug report, #1, #2, and #3 all still exist in codelite 11.0

Has anyone every managed to get this to function correctly?

ywrt commented Oct 23, 2017

This doesn't appear to be fixed still. I'm running codelite 11.0, and it still creates blank test files.

Steps:

  1. Added unittest++ project per http://codelite.org/LiteEditor/UnitTestPP
  2. Right-click, select 'unitest++/Create tests for class'.
  3. Untick a couple of functions I don't need tests for, leaving one.
  4. Add 'mapper_test.cpp' as an output function.

Result: I get a 'mapper_test.cpp' file that contains the single line '#include <UnitTest++.h>' and nothing else. No errors are reported, it just doesn't work correctly.

If I manually add a test, it fails because the project doesnt know anything about the paths to the original.

Basically, from the original bug report, #1, #2, and #3 all still exist in codelite 11.0

Has anyone every managed to get this to function correctly?

@eranif

This comment has been minimized.

Show comment
Hide comment
@eranif

eranif Oct 23, 2017

Owner

I am not sure what are you doing, but this works for me.
Right click on a source file (or from the menu: plugins->unittest++->Create test for class)
I checked one function, and I got this:

#include <unittest++/UnitTest++.h>

TEST(TestTesterClass_foo)
{
}

If I manually add a test, it fails because the project doesnt know anything about the paths to the original.

I am not sure what this means - you mean: it does not compile? if this is the case, then yes, you will need to edit the UT project ti know where your classes exist (include files and library to link against)

FYI:
The plugin purpose is to give you a nice report, it does not auto-link compile your source against any class of your choice.

Owner

eranif commented Oct 23, 2017

I am not sure what are you doing, but this works for me.
Right click on a source file (or from the menu: plugins->unittest++->Create test for class)
I checked one function, and I got this:

#include <unittest++/UnitTest++.h>

TEST(TestTesterClass_foo)
{
}

If I manually add a test, it fails because the project doesnt know anything about the paths to the original.

I am not sure what this means - you mean: it does not compile? if this is the case, then yes, you will need to edit the UT project ti know where your classes exist (include files and library to link against)

FYI:
The plugin purpose is to give you a nice report, it does not auto-link compile your source against any class of your choice.

@ywrt

This comment has been minimized.

Show comment
Hide comment
@ywrt

ywrt Oct 23, 2017

I'm assuming you didn't enter an output filename? (Because if so, that the #include should be <UnitTest++.h> according to https://github.com/eranif/codelite/blob/master/UnitTestCPP/unittestpp.cpp#L432 ?)
Hmm. Actually, it doesn't work either way for me.

As far as I can tell, DoAddTestFile() returns NULL for reasons unknown.

Given that adding the unittest fails both when creating the test.cpp file, and when the test.cpp file already exists, I suspect that editor->GetFileName() != fn. This is a condition checked in line 451 and 468, that causes silent failures if they differ.

It's unclear to me why the check is there at all?

    m_mgr->OpenFile(fn.GetFullPath());
    editor = m_mgr->GetActiveEditor();
    if(editor && editor->GetFileName() == fn) {
            return editor;
    }

We just opened the fully qualified fn.GetFullPath(): How can editor->GetFileName() be different in a meaningful way?

The other silent failure is failing to find the project (i.e. m_mgr->GetWorkspace()->FindProjectByName(projectName, errMsg) == NULL), but as far as I can tell, that's not happening because the test.cpp file is added to the project (it appears on the 'Workspace' tab).

Re the FYI: That's somewhat disappointing. Is there any documentation that describes how to unittest a c++ project in codelite? I'm guessing that I should setup 3 projects in a workspace? One that builds a library, one that builds an executable and links against that library, and one that builds tests and also links against the same library? And then manually add in all the paths for includes and libraries etc?

ywrt commented Oct 23, 2017

I'm assuming you didn't enter an output filename? (Because if so, that the #include should be <UnitTest++.h> according to https://github.com/eranif/codelite/blob/master/UnitTestCPP/unittestpp.cpp#L432 ?)
Hmm. Actually, it doesn't work either way for me.

As far as I can tell, DoAddTestFile() returns NULL for reasons unknown.

Given that adding the unittest fails both when creating the test.cpp file, and when the test.cpp file already exists, I suspect that editor->GetFileName() != fn. This is a condition checked in line 451 and 468, that causes silent failures if they differ.

It's unclear to me why the check is there at all?

    m_mgr->OpenFile(fn.GetFullPath());
    editor = m_mgr->GetActiveEditor();
    if(editor && editor->GetFileName() == fn) {
            return editor;
    }

We just opened the fully qualified fn.GetFullPath(): How can editor->GetFileName() be different in a meaningful way?

The other silent failure is failing to find the project (i.e. m_mgr->GetWorkspace()->FindProjectByName(projectName, errMsg) == NULL), but as far as I can tell, that's not happening because the test.cpp file is added to the project (it appears on the 'Workspace' tab).

Re the FYI: That's somewhat disappointing. Is there any documentation that describes how to unittest a c++ project in codelite? I'm guessing that I should setup 3 projects in a workspace? One that builds a library, one that builds an executable and links against that library, and one that builds tests and also links against the same library? And then manually add in all the paths for includes and libraries etc?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment