[education/rkward/kf5] rkward: Require tests not to produce error messages
Thomas Friedrichsmeier
null at kde.org
Wed Apr 10 16:12:08 BST 2024
Git commit f1b4269d040b6462d14e4f2693da9cbd80ea8e34 by Thomas Friedrichsmeier.
Committed on 06/04/2024 at 11:27.
Pushed by tfry into branch 'kf5'.
Require tests not to produce error messages
M +17 -5 rkward/autotests/core_test.cpp
M +1 -1 rkward/core/rcontainerobject.cpp
M +1 -1 rkward/core/renvironmentobject.cpp
M +3 -1 rkward/rbackend/rkrinterface.cpp
M +11 -10 rkward/rbackend/rkrsupport.cpp
https://invent.kde.org/education/rkward/-/commit/f1b4269d040b6462d14e4f2693da9cbd80ea8e34
diff --git a/rkward/autotests/core_test.cpp b/rkward/autotests/core_test.cpp
index f8ac4751b..c08579700 100644
--- a/rkward/autotests/core_test.cpp
+++ b/rkward/autotests/core_test.cpp
@@ -1,6 +1,6 @@
/*
core_test - This file is part of RKWard (https://rkward.kde.org). Created: Thu Jun 09 2022
-SPDX-FileCopyrightText: 2022 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2024 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
@@ -44,10 +44,11 @@ void testLog(const char* fmt, ...) {
va_end(ap);
}
-void RKDebug (int, int, const char* fmt, ...) {
+void RKDebug (int, int level, const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
testLog(fmt, ap);
+ if (level >= DL_ERROR) QFAIL("error message during test (see above)");
va_end(ap);
}
@@ -89,10 +90,20 @@ class RKWardCoreTest: public QObject {
}
void listBackendLog() {
- testLog("Listing contents of /tmp/rkward.rbackend");
+ testLog("Listing (new) contents of /tmp/rkward.rbackend");
QFile f(QDir::tempPath() + "/rkward.rbackend");
f.open(QIODevice::ReadOnly);
auto output = f.readAll();
+ QFile fl(QDir::tempPath() + "/rkward.rbackend.listed");
+ fl.open(QIODevice::ReadOnly);
+ auto oldoutput = fl.readAll();
+ fl.close();
+ fl.open(QIODevice::ReadWrite | QIODevice::Truncate);
+ fl.write(output);
+ fl.close();
+ if (output.startsWith(oldoutput)) {
+ output = output.mid(oldoutput.length());
+ }
testLog("%s", output.data());
}
@@ -126,6 +137,7 @@ private Q_SLOTS:
void cleanup() {
testLog("Cleanup. Backend status: %s", qPrintable(backendStatus()));
waitForAllFinished();
+ listBackendLog();
testLog("Cleanup done. Backend status: %s", qPrintable(backendStatus()));
}
@@ -149,7 +161,7 @@ private Q_SLOTS:
}
void getIntVector() {
- auto c = new RCommand("c(1, 2, 3)", RCommand::GetIntVector);
+ auto c = new RCommand("c(1, 2, 3)", RCommand::GetIntVector | RCommand::App);
runCommandWithTimeout(c, nullptr, [](RCommand *command) {
QCOMPARE(command->getDataType(), RData::IntVector);
QCOMPARE(command->getDataLength(), 3);
@@ -208,7 +220,7 @@ private Q_SLOTS:
}
dx->rename("dy");
}
- auto c = new RCommand("dy$c", RCommand::GetIntVector);
+ auto c = new RCommand("dy$c", RCommand::GetIntVector | RCommand::App);
runCommandAsync(c, nullptr, [](RCommand *command) {
QCOMPARE(command->getDataType(), RData::IntVector);
QCOMPARE(command->getDataLength(), 2);
diff --git a/rkward/core/rcontainerobject.cpp b/rkward/core/rcontainerobject.cpp
index 79e561dfd..676b56259 100644
--- a/rkward/core/rcontainerobject.cpp
+++ b/rkward/core/rcontainerobject.cpp
@@ -316,7 +316,7 @@ void RContainerObject::renameChild (RObject *object, const QString &new_name) {
}
RCommand *command = new RCommand (renameChildCommand (object, new_name), RCommand::App | RCommand::Sync);
- command->setUpdatesObject(this);
+ command->setUpdatesObject(object); // NOTE will be mapped to toplevel object, anyway
RInterface::issueCommand(command, nullptr);
object->name = new_name;
diff --git a/rkward/core/renvironmentobject.cpp b/rkward/core/renvironmentobject.cpp
index 533a8b3f3..cb5b496ae 100644
--- a/rkward/core/renvironmentobject.cpp
+++ b/rkward/core/renvironmentobject.cpp
@@ -95,7 +95,7 @@ void REnvironmentObject::updateFromR(RCommandChain *chain, const QStringList &ad
for (int i = removed_symbols.size() -1; i >= 0; --i) {
RObject *removed_object = findChildByName(removed_symbols[i]);
- RK_ASSERT(removed_object);
+ if(!removed_object) RK_DEBUG(OBJECTS, DL_ERROR, "Removed object %s was not registered", qPrintable(removed_symbols[i]));
if (removed_object) RKModificationTracker::instance()->removeObject(removed_object, nullptr, true);
}
diff --git a/rkward/rbackend/rkrinterface.cpp b/rkward/rbackend/rkrinterface.cpp
index a3ea50ef2..a9ec01280 100644
--- a/rkward/rbackend/rkrinterface.cpp
+++ b/rkward/rbackend/rkrinterface.cpp
@@ -537,7 +537,9 @@ void RInterface::cancelAll () {
RK_TRACE (RBACKEND);
const QList<RCommand*> all_commands = RCommandStack::regular_stack->allCommands ();
- for (RCommand* command : all_commands) cancelCommand (command);
+ for (RCommand* command : all_commands) {
+ if (!(command->type() & RCommand::Sync)) cancelCommand(command);
+ }
}
bool RInterface::softCancelCommand (RCommand* command) {
diff --git a/rkward/rbackend/rkrsupport.cpp b/rkward/rbackend/rkrsupport.cpp
index 615ce2336..552e53845 100644
--- a/rkward/rbackend/rkrsupport.cpp
+++ b/rkward/rbackend/rkrsupport.cpp
@@ -322,16 +322,6 @@ void RKRShadowEnvironment::updateCacheForGlobalenvSymbol(const QString& name) {
environmentFor(R_GlobalEnv)->updateSymbolCache(name);
}
-void RKRShadowEnvironment::updateSymbolCache(const QString& name) {
- RK_TRACE(RBACKEND);
- SEXP rname = Rf_installChar(Rf_mkCharCE(name.toUtf8().constData(), CE_UTF8));
- PROTECT(rname);
- SEXP symbol_g = Rf_findVar(rname, R_GlobalEnv);
- PROTECT(symbol_g);
- Rf_defineVar(rname, symbol_g, shadowenvir);
- UNPROTECT(2);
-}
-
static void unbindSymbolWrapper(SEXP name, SEXP env) {
#if R_VERSION >= R_Version(4, 0, 0)
R_removeVarFromFrame(name, env);
@@ -348,6 +338,17 @@ static void unbindSymbolWrapper(SEXP name, SEXP env) {
#endif
}
+void RKRShadowEnvironment::updateSymbolCache(const QString& name) {
+ RK_TRACE(RBACKEND);
+ SEXP rname = Rf_installChar(Rf_mkCharCE(name.toUtf8().constData(), CE_UTF8));
+ PROTECT(rname);
+ SEXP symbol_g = Rf_findVar(rname, R_GlobalEnv);
+ PROTECT(symbol_g);
+ if (symbol_g == R_UnboundValue) unbindSymbolWrapper(rname, shadowenvir);
+ else Rf_defineVar(rname, symbol_g, shadowenvir);
+ UNPROTECT(2);
+}
+
RKRShadowEnvironment::Result RKRShadowEnvironment::diffAndUpdate() {
RK_TRACE (RBACKEND);
Result res;
More information about the rkward-tracker
mailing list