@@ -160,6 +160,16 @@ class TestCmdlineParser : public TestFixture {
160160 TEST_CASE(templatesGcc);
161161 TEST_CASE(templatesVs);
162162 TEST_CASE(templatesEdit);
163+ TEST_CASE(templatesCppcheck1);
164+ TEST_CASE(templatesDaca2);
165+ TEST_CASE(templatesSelfcheck);
166+ TEST_CASE(templatesNoPlaceholder);
167+ TEST_CASE(templateFormatInvalid);
168+ TEST_CASE(templateFormatInvalid2);
169+ TEST_CASE(templateFormatEmpty);
170+ TEST_CASE(templateLocationInvalid);
171+ TEST_CASE(templateLocationInvalid2);
172+ TEST_CASE(templateLocationEmpty);
163173 TEST_CASE(xml);
164174 TEST_CASE(xmlver2);
165175 TEST_CASE(xmlver2both);
@@ -1220,23 +1230,28 @@ class TestCmdlineParser : public TestFixture {
12201230
12211231 void templates() {
12221232 REDIRECT;
1223- const char * const argv[] = {" cppcheck" , " --template" , " {file}:{line},{severity},{id},{message}" , " file.cpp" };
1233+ const char * const argv[] = {"cppcheck", "--template", "{file}:{line},{severity},{id},{message}", "--template-location={file}:{line}:{column} {info}", " file.cpp"};
12241234 settings.templateFormat.clear();
1235+ settings.templateLocation.clear();
12251236 ASSERT(defParser.parseFromArgs(4, argv));
12261237 ASSERT_EQUALS("{file}:{line},{severity},{id},{message}", settings.templateFormat);
1238+ ASSERT_EQUALS("{file}:{line}:{column} {info}", settings.templateLocation);
12271239 ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
12281240 }
12291241
12301242 void templatesGcc() {
12311243 REDIRECT;
12321244 const char * const argv[] = {"cppcheck", "--template", "gcc", "file.cpp"};
12331245 settings.templateFormat.clear();
1246+ settings.templateLocation.clear();
12341247 ASSERT(defParser.parseFromArgs(4, argv));
12351248 if (isStdOutATty()) {
12361249 ASSERT_EQUALS("\x1b[1m{file}:{line}:{column}: \x1b[35mwarning:\x1b[39m {message} [{id}]\x1b[0m\n{code}", settings.templateFormat);
1250+ ASSERT_EQUALS("\x1b[1m{file}:{line}:{column}: \x1b[2mnote:\x1b[0m {info}\n{code}", settings.templateLocation);
12371251 }
12381252 else {
12391253 ASSERT_EQUALS("{file}:{line}:{column}: warning: {message} [{id}]\n{code}", settings.templateFormat);
1254+ ASSERT_EQUALS("{file}:{line}:{column}: note: {info}\n{code}", settings.templateLocation);
12401255 }
12411256 ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
12421257 }
@@ -1245,17 +1260,148 @@ class TestCmdlineParser : public TestFixture {
12451260 REDIRECT;
12461261 const char * const argv[] = {"cppcheck", "--template", "vs", "file.cpp"};
12471262 settings.templateFormat.clear();
1263+ settings.templateLocation.clear();
12481264 ASSERT(defParser.parseFromArgs(4, argv));
12491265 ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings.templateFormat);
1266+ ASSERT_EQUALS("", settings.templateLocation);
12501267 ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
12511268 }
12521269
12531270 void templatesEdit() {
12541271 REDIRECT;
12551272 const char * const argv[] = {"cppcheck", "--template", "edit", "file.cpp"};
12561273 settings.templateFormat.clear();
1274+ settings.templateLocation.clear();
12571275 ASSERT(defParser.parseFromArgs(4, argv));
12581276 ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings.templateFormat);
1277+ ASSERT_EQUALS("", settings.templateLocation);
1278+ ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1279+ }
1280+
1281+ void templatesCppcheck1() {
1282+ REDIRECT;
1283+ const char * const argv[] = {"cppcheck", "--template=cppcheck1", "file.cpp"};
1284+ settings.templateFormat.clear();
1285+ settings.templateLocation.clear();
1286+ ASSERT(defParser.parseFromArgs(3, argv));
1287+ ASSERT_EQUALS("{callstack}: ({severity}{inconclusive:, inconclusive}) {message}", settings.templateFormat);
1288+ ASSERT_EQUALS("", settings.templateLocation);
1289+ ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1290+ }
1291+
1292+ void templatesDaca2() {
1293+ REDIRECT;
1294+ const char * const argv[] = {"cppcheck", "--template=daca2", "file.cpp"};
1295+ settings.templateFormat.clear();
1296+ settings.templateLocation.clear();
1297+ ASSERT(defParser.parseFromArgs(3, argv));
1298+ ASSERT_EQUALS("{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]", settings.templateFormat);
1299+ ASSERT_EQUALS("{file}:{line}:{column}: note: {info}", settings.templateLocation);
1300+ ASSERT_EQUALS(true, settings.daca);
1301+ ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1302+ }
1303+
1304+ void templatesSelfcheck() {
1305+ REDIRECT;
1306+ const char * const argv[] = {"cppcheck", "--template=selfcheck", "file.cpp"};
1307+ settings.templateFormat.clear();
1308+ settings.templateLocation.clear();
1309+ ASSERT(defParser.parseFromArgs(3, argv));
1310+ ASSERT_EQUALS("{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]\n{code}", settings.templateFormat);
1311+ ASSERT_EQUALS("{file}:{line}:{column}: note: {info}\n{code}", settings.templateLocation);
1312+ ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1313+ }
1314+
1315+ // TODO: we should bail out on this
1316+ void templatesNoPlaceholder() {
1317+ REDIRECT;
1318+ const char * const argv[] = {"cppcheck", "--template=selfchek", "file.cpp"};
1319+ settings.templateFormat.clear();
1320+ settings.templateLocation.clear();
1321+ TODO_ASSERT(!defParser.parseFromArgs(3, argv));
1322+ ASSERT_EQUALS("selfchek", settings.templateFormat);
1323+ ASSERT_EQUALS("", settings.templateLocation);
1324+ ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1325+ }
1326+
1327+ void templateFormatInvalid() {
1328+ REDIRECT;
1329+ const char* const argv[] = { "cppcheck", "--template", "--template-location={file}", "file.cpp" };
1330+ ASSERT(!defParser.parseFromArgs(4, argv));
1331+ ASSERT_EQUALS("cppcheck: error: argument to '--template' is missing.\n", GET_REDIRECT_OUTPUT);
1332+ }
1333+
1334+ // TODO: will not error out as he next option does not start with a "-"
1335+ void templateFormatInvalid2() {
1336+ REDIRECT;
1337+ settings.templateFormat.clear();
1338+ settings.templateLocation.clear();
1339+ const char* const argv[] = { "cppcheck", "--template", "file.cpp" };
1340+ TODO_ASSERT(!defParser.parseFromArgs(3, argv));
1341+ ASSERT_EQUALS("file.cpp", settings.templateFormat);
1342+ ASSERT_EQUALS("", settings.templateLocation);
1343+ ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1344+ }
1345+
1346+ // will use the default
1347+ // TODO: bail out on empty?
1348+ void templateFormatEmpty() {
1349+ REDIRECT;
1350+ settings.templateFormat.clear();
1351+ settings.templateLocation.clear();
1352+ const char* const argv[] = { "cppcheck", "--template=", "file.cpp" };
1353+ ASSERT(defParser.parseFromArgs(3, argv));
1354+ if (isStdOutATty()) {
1355+ ASSERT_EQUALS("\x1b[1m{file}:{line}:{column}: \x1b[31m{inconclusive:\x1b[35m}{severity}:{inconclusive: inconclusive:}\x1b[39m {message} [{id}]\x1b[0m\n{code}", settings.templateFormat);
1356+ ASSERT_EQUALS("\x1b[1m{file}:{line}:{column}: \x1b[2mnote:\x1b[0m {info}\n{code}", settings.templateLocation);
1357+ }
1358+ else {
1359+ ASSERT_EQUALS("{file}:{line}:{column}: {inconclusive:}{severity}:{inconclusive: inconclusive:} {message} [{id}]\n{code}", settings.templateFormat);
1360+ ASSERT_EQUALS("{file}:{line}:{column}: note: {info}\n{code}", settings.templateLocation);
1361+ }
1362+ ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1363+ }
1364+
1365+ void templateLocationInvalid() {
1366+ REDIRECT;
1367+ const char* const argv[] = { "cppcheck", "--template-location", "--template={file}", "file.cpp" };
1368+ ASSERT(!defParser.parseFromArgs(4, argv));
1369+ ASSERT_EQUALS("cppcheck: error: argument to '--template-location' is missing.\n", GET_REDIRECT_OUTPUT);
1370+ }
1371+
1372+ // TODO: will not error out as he next option does not start with a "-"
1373+ void templateLocationInvalid2() {
1374+ REDIRECT;
1375+ settings.templateFormat.clear();
1376+ settings.templateLocation.clear();
1377+ const char* const argv[] = { "cppcheck", "--template-location", "file.cpp" };
1378+ TODO_ASSERT(!defParser.parseFromArgs(3, argv));
1379+ if (isStdOutATty()) {
1380+ ASSERT_EQUALS("\x1b[1m{file}:{line}:{column}: \x1b[31m{inconclusive:\x1b[35m}{severity}:{inconclusive: inconclusive:}\x1b[39m {message} [{id}]\x1b[0m\n{code}", settings.templateFormat);
1381+ }
1382+ else {
1383+ ASSERT_EQUALS("{file}:{line}:{column}: {inconclusive:}{severity}:{inconclusive: inconclusive:} {message} [{id}]\n{code}", settings.templateFormat);
1384+ }
1385+ ASSERT_EQUALS("file.cpp", settings.templateLocation);
1386+ ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1387+ }
1388+
1389+ // will use the default
1390+ // TODO: bail out on empty?
1391+ void templateLocationEmpty() {
1392+ REDIRECT;
1393+ settings.templateFormat.clear();
1394+ settings.templateLocation.clear();
1395+ const char* const argv[] = { "cppcheck", "--template-location=", "file.cpp" };
1396+ ASSERT(defParser.parseFromArgs(3, argv));
1397+ if (isStdOutATty()) {
1398+ ASSERT_EQUALS("\x1b[1m{file}:{line}:{column}: \x1b[31m{inconclusive:\x1b[35m}{severity}:{inconclusive: inconclusive:}\x1b[39m {message} [{id}]\x1b[0m\n{code}", settings.templateFormat);
1399+ ASSERT_EQUALS("\x1b[1m{file}:{line}:{column}: \x1b[2mnote:\x1b[0m {info}\n{code}", settings.templateLocation);
1400+ }
1401+ else {
1402+ ASSERT_EQUALS("{file}:{line}:{column}: {inconclusive:}{severity}:{inconclusive: inconclusive:} {message} [{id}]\n{code}", settings.templateFormat);
1403+ ASSERT_EQUALS("{file}:{line}:{column}: note: {info}\n{code}", settings.templateLocation);
1404+ }
12591405 ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
12601406 }
12611407
0 commit comments