Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Common/CodeGen/tests/GrantleeParserSmoke.cpp
T
torstenandCopilot d6b6ffce7c Apply clang-format to Lts/Common and DTC/enum headers
- Formatted all CodeGen module files (9 files)
- Formatted LtsAppDescriptor module files
- Formatted LtsAppManager/AppChooser files
- Applied clang-format to all DTC and enum headers across modules
- Removed coordTransTests from CommonUnitTestsPlaceholder (moved to tests/)

Cosmetic changes only, no functional modifications.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-19 14:46:29 +02:00

71 lines
1.8 KiB
C++

#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <grantlee/engine.h>
#include <grantlee/templateloader.h>
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
QString templatesDir = QDir::currentPath();
if (argc > 1)
{
templatesDir = QString::fromLocal8Bit(argv[1]);
}
Grantlee::Engine engine;
auto loader = QSharedPointer<Grantlee::FileSystemTemplateLoader>::create();
loader->setTemplateDirs(QStringList() << templatesDir);
engine.addTemplateLoader(loader);
QDir d(templatesDir);
QStringList files = d.entryList(QStringList() << QStringLiteral("*.grantlee"), QDir::Files);
if (files.isEmpty())
{
qDebug() << "No .grantlee templates found in" << templatesDir;
// Treat absence as successful parse (nothing to check) to avoid failing
// when directory is empty in different setups.
return 0;
}
bool ok = true;
for (const QString& f : files)
{
Grantlee::Template t;
try
{
t = engine.loadByName(f);
}
catch (...)
{
qDebug() << "Exception while loading" << f;
ok = false;
continue;
}
if (!t)
{
qDebug() << "Failed to load template" << f;
ok = false;
continue;
}
if (t->error() != Grantlee::NoError)
{
qDebug() << "Parse error in" << f << ":" << t->errorString();
ok = false;
continue;
}
// Render with empty context to ensure rendering path also works.
Grantlee::Context ctx;
QString out = t->render(&ctx);
if (out.isNull())
{
qDebug() << "Rendering produced null for" << f;
ok = false;
continue;
}
}
return ok ? 0 : 2;
}