Commit 4a9ca0ec authored by Alexander Semke's avatar Alexander Semke
Browse files

[maxima] in case a warning is produced, treat it as such by adding and new...

[maxima] in case a warning is produced, treat it as such by adding and new text result and don't set the status of the expression to Error.
parent cb516942
Pipeline #119096 passed with stage
in 18 minutes and 54 seconds
......@@ -219,8 +219,18 @@ bool MaximaExpression::parseOutput(QString& out)
//parse the results
int resultStart = out.indexOf(QLatin1String("<cantor-result>"));
if (resultStart != -1)
if (resultStart != -1) {
errorContent += out.mid(0, resultStart);
if (!errorContent.isEmpty() && ! (m_isHelpRequest || m_isHelpRequestAdditional))
{
//there is a result but also the error buffer is not empty. This is the case when
//warnings are generated, for example, the output of rat(0.75*10) is:
//"\nrat: replaced 7.5 by 15/2 = 7.5\n<cantor-result><cantor-text>\n(%o2) 15/2\n</cantor-text></cantor-result>\n<cantor-prompt>(%i3) </cantor-prompt>\n".
//In such cases we just add a new text result with the warning.
qDebug() << "warning: " << errorContent;
addResult(new Cantor::TextResult(errorContent.trimmed()));
}
}
while (resultStart != -1)
{
......@@ -250,11 +260,13 @@ bool MaximaExpression::parseOutput(QString& out)
{
qDebug() << "error content: " << errorContent;
if (out.contains(QLatin1String("cantor-value-separator")))
if (out.contains(QLatin1String("cantor-value-separator")) || out.contains(QLatin1String("<cantor-result>")))
{
//when fetching variables, in addition to the actual result with variable names and values,
//Maxima also writes out the names of the variables to the error buffer.
//we don't interpret this as an error.
//we don't interpret the error output as an error in the following cases:
//1. when fetching variables, in addition to the actual result with variable names and values,
// Maxima also writes out the names of the variables to the error buffer.
//2. when there is a valid result produced, in this case the error string
// contains actually a warning that is handled above
setStatus(Cantor::Expression::Done);
}
else if(m_isHelpRequest || m_isHelpRequestAdditional) //help messages are also part of the error output
......
......@@ -107,6 +107,21 @@ void TestMaxima::testInvalidSyntax()
QVERIFY( e->status()==Cantor::Expression::Error );
}
void TestMaxima::testWarning()
{
auto* e = evalExp( QLatin1String("rat(0.75*10)") );
QVERIFY(e != nullptr);
QVERIFY(e->results().size() == 2); //two results, the warning and the actual result of the calculation
//the actual warning string "rat: replaced 7.5 by 15/2 = 7.5" which we don't checked since it's translated,
//we just check it's existance.
QVERIFY(e->results().at(0)->data().toString().isEmpty() == false);
//the result of the calculation
QCOMPARE(e->results().at(1)->data().toString(), QLatin1String("15/2"));
}
void TestMaxima::testExprNumbering()
{
Cantor::Expression* e=evalExp( QLatin1String("kill(labels)") ); //first reset the labels
......
......@@ -28,22 +28,26 @@ private Q_SLOTS:
void testPlot();
void testPlotWithAnotherTextResults();
/* errors and warnings */
//tests a syntax error (not closing bracket)
void testInvalidSyntax();
void testWarning();
//tests if the expression numbering works
void testExprNumbering();
void testInvalidAssignment();
//some tests to see if comments are working correctly
/* comments */
void testSimpleExpressionWithComment();
void testCommentExpression();
void testNestedComment();
void testUnmatchedComment();
void testInvalidAssignment();
/* tests where additional input is required */
void testInformationRequest();
void testHelpRequest();
void testSyntaxHelp();
void testCompletion();
void testVariableModel();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment