Well actually not. If you comment the line cctest does simply nothing. At least not on my pc...
That was strange, I just comment the line
m_NativeParser.Parse(m_CurrentFile);
But if you look at the code:
bool NativeParserTest::TestParseAndCodeCompletion(wxString filename)
{
Clear();//clear the tree
bool parseResult = false;
parseResult = Parse(filename);
if(!parseResult)
return false;
int passCount = 0;
int failCount = 0;
wxString testResult;
wxString message = wxString::Format(_T("********************************************************\n Testing in file: %s\n********************************************************"),filename.wx_str());
wxLogMessage(message);
testResult<<message<<wxT("\n");
// read the test cases of CodeCompletion test
wxTextFile source;
source.Open(filename);
wxString str;
for ( str = source.GetLastLine();
source.GetCurrentLine() > 0;
str = source.GetPrevLine() )
{
// a test case should be put in a line, and start with the double slash
if (str.StartsWith(_T("//")))
{
// do tests here, example of line is below
// tc.St //StaticVoid
// remove the beginning "//"
str.Remove(0,2);
// find the second "//", the string after the second double slash are the
// the result should be listed
wxString expression;
wxString match;
int pos = str.Find(_T("//"));
if (pos == wxNOT_FOUND)
break;
expression = str.Mid(0,pos);
match = str.Mid(pos+2);// the remaining string
expression.Trim();
expression.Trim(true);
match.Trim();
match.Trim(true);
wxArrayString suggestList;
// the match can have many items, like: AAA,BBBB
wxStringTokenizer tkz(match, wxT(","));
while ( tkz.HasMoreTokens() )
{
wxString token = tkz.GetNextToken();
suggestList.Add(token);
}
TokenIdxSet searchScope;
searchScope.insert(-1);
TokenIdxSet result;
TestExpression(expression,searchScope,result);
// loop the suggestList to see it is in the result Tokens
for (size_t i=0;i<suggestList.GetCount();i++)
{
wxString element = suggestList[i];
bool pass = false; // pass the test?
for (TokenIdxSet::const_iterator it = result.begin();
it != result.end();
++it)
{
const Token* token = m_Parser.GetTokenTree()->at(*it);
if (!token || token->m_Name.IsEmpty())
continue;
if (element.IsSameAs(token->m_Name))
{
message = wxString::Format(_T("-PASS: %s %s"),expression.wx_str(),element.wx_str());
testResult<<message<<wxT("\n");
wxLogMessage(message);
pass = true;
passCount++;
}
}
if (pass == false)
{
message = wxString::Format(_T("*FAIL: %s %s"),expression.wx_str(),element.wx_str());
testResult<<message<<wxT("\n");
wxLogMessage(message);
failCount++;
}
}
// wxLogMessage(_T("Result have %lu matches"), static_cast<unsigned long>(result.size()));
}
else
break; // if the line is not started with //, then we just stop testing
}
// report the test result here again in the last stage, further more, we can show this in another text control
wxLogMessage(wxT("--------------------------------------------------------\nTotal %d tests, %d PASS, %d FAIL\n--------------------------------------------------------"), passCount+failCount, passCount, failCount);
return true;
}
You see, the steps of NativeParserTest::TestParseAndCodeCompletion is:
1, clear the TokenTree
2, parse the file
3, run tests
4, report fail and pass results.
BTW: Here is the log message I see:
000001. --------------M-a-i-n--L-o-g--------------
000002. -----------I-n-t-e-r-i-m--L-o-g-----------
********************************************************
Testing in file: C:\DOCUME~1\zyh23\LOCALS~2\Temp\cc125.h
********************************************************
*FAIL: vt[1]. GetInt
-PASS: g_S. i
-PASS: g_ g_S
-PASS: tc.Vo Void
-PASS: tc.St StaticVoid
-PASS: tc.GetC GetClass
-PASS: tc.GetI GetInt
-PASS: str. size
-PASS: str. length
--------------------------------------------------------
Total 9 tests, 8 PASS, 1 FAIL
--------------------------------------------------------
Note that I remove CC_PARSER_TEST macro definition in rev9644 (see the bold text below), since it run our test much faster, in the future, we can run many tests in a single run(we can have many cc_xxxxx files which contains many kinds of tests, then our cctest project test them one by one)
SHA-1: 40c5a4c8323e26aad488c536d426d1ab34cc66a5
* * cctest: add a framework of codecompletion test, the details are listed in C::B forum topic (batch codecompletion test framework - http://forums.codeblocks.org/index.php/topic,17538.msg120196.html#msg120196)
1, remove the file cctest.h and cctest.cpp, because those standalone classes/functions were moved to NativeParserTest class (derived from NativeParserBase), so a lot of functions can be reused from NativeParserBase.
2, remove CC_PARSER_TEST definition to reduce parser log messages, only show codecompletion test result and the show fail and pass testing counts. If the user need to see the full parser log messages, they should define them, which will plot a log of log messages.
3, redirect the wxLogMessage to the text ctrl of the frame.
4, fix typo in comments, and add some comments.
5, project target setting change, make it a gui app instead of console app, and redirect the wxLogMessage to the wxTextCtrl.
6, set the default parsing file to testing/cc_function_decls.cpp, not the default test.h
7, add the wxsmith file to cbp, so it can be opened quickly from the project manager.
8, by default, Token tree structure is not logged, but it can be logged by click the "Print Tree" button.
9, add some string variable to the wx and gcc search path, avoid the hard-coded path.
git-svn-id: https://svn.code.sf.net/p/codeblocks/code/trunk@9644 2a5c6006-c6dd-42ca-98ab-0921f2732cef