migration(grantlee): add patch script to avoid QT_TESTCASE_BUILDDIR redefinition; add Grantlee parser smoke test
This commit is contained in:
1 parent
faa891b573
commit
56adad890c
3 files changed
+107
No files matched your search
@@ -0,0 +1,62 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
|
||||
#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() << "*.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::TemplateImpl::Error::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;
|
||||
}
|
||||
Reference in new issue
Block a user