1
/* KDevelop CMake Support
3
* Copyright 2006 Matt Rogers <mattr@kde.org>
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
#include "cmakeparsertest.h"
23
#include <KTemporaryFile>
24
#include "cmListFileLexer.h"
25
#include "cmakelistsparser.h"
28
QTEST_MAIN( CMakeParserTest )
30
CMakeParserTest::CMakeParserTest()
33
CMakeParserTest::~CMakeParserTest()
36
void CMakeParserTest::testLexerCreation()
38
cmListFileLexer* lexer = cmListFileLexer_New();
39
QVERIFY( lexer != 0 );
40
cmListFileLexer_Delete( lexer );
43
void CMakeParserTest::testLexerWithFile()
45
QTemporaryFile tempFile;
46
tempFile.setAutoRemove( false );
48
if ( !QFile::exists( tempFile.fileName() ) )
49
QFAIL( "Unable to open temporary file" );
51
QString tempName = tempFile.fileName();
52
tempFile.close(); //hacks to the get name of the file
54
cmListFileLexer* lexer = cmListFileLexer_New();
56
QFAIL( "unable to create lexer" );
57
QVERIFY( cmListFileLexer_SetFileName( lexer, qPrintable( tempName ) ) );
58
cmListFileLexer_Delete( lexer );
62
void CMakeParserTest::testParserWithGoodData()
64
// QFAIL( "the magic is missing" );
65
QFETCH( QString, text );
66
QTemporaryFile tempFile;
67
tempFile.setAutoRemove( false );
69
if ( !QFile::exists( tempFile.fileName() ) )
70
QFAIL( "Unable to open temporary file" );
72
tempFile.write( text.toUtf8() );
73
QString tempName = tempFile.fileName();
74
tempFile.close(); //hacks to the get name of the file
75
// CMakeAst* ast = new CMakeAst;
76
// bool parseError = CMakeListsParser::parseCMakeFile( ast, qPrintable( tempName ) );
78
// QVERIFY( parseError == false );
82
void CMakeParserTest::testParserWithGoodData_data()
84
QTest::addColumn<QString>( "text" );
85
QTest::newRow( "good data1" ) << "project(foo)\nset(foobar_SRCS foo.h foo.c)";
86
QTest::newRow( "good data2" ) << "set(foobar_SRCS foo.h foo.c)\n"
87
"add_executable( foo ${foobar_SRCS})";
90
void CMakeParserTest::testParserWithBadData()
92
QFETCH( QString, text );
93
QTemporaryFile tempFile;
94
tempFile.setAutoRemove( false );
96
if ( !QFile::exists( tempFile.fileName() ) )
97
QFAIL( "Unable to open temporary file" );
99
tempFile.write( text.toUtf8() );
100
QString tempName = tempFile.fileName();
101
tempFile.close(); //hacks to the get name of the file
102
// CMakeAst* ast = new CMakeAst;
103
// bool parseError = CMakeListsParser::parseCMakeFile( ast, qPrintable( tempName ) );
105
// QVERIFY( parseError == true );
109
void CMakeParserTest::testParserWithBadData_data()
111
QTest::addColumn<QString>( "text" );
113
//just plain wrong. :)
114
QTest::newRow( "bad data 1" ) << "foo bar baz zippedy do dah";
116
//missing right parenthesis
117
QTest::newRow( "bad data 2" ) << "set(mysrcs_SRCS foo.c\n\n\n";
119
//extra identifiers between functions. cmake doesn't allow plain identifiers
120
QTest::newRow( "bad data 3" ) << "the(quick) brown fox jumped(over) the lazy dog";
122
//invalid due to no newline before next command
123
QTest::newRow( "bad data 4" ) << "project(foo) set(mysrcs_SRCS foo.c)";
126
// void CMakeParserTest::testAstCreation()
131
#include "cmakeparsertest.moc"