Skip to content

Commit

Permalink
Refs #4316: MantidPlot unit test set an exit code
Browse files Browse the repository at this point in the history
so that ctest recognizes them as failed when they do.
  • Loading branch information
Janik Zikovsky committed Dec 24, 2011
1 parent f59023a commit 23fa76a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
24 changes: 23 additions & 1 deletion Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void file_uncompress(const char *file);


ApplicationWindow::ApplicationWindow(bool factorySettings)
: QMainWindow(), Scripted(ScriptingLangManager::newEnv(this))
: QMainWindow(), Scripted(ScriptingLangManager::newEnv(this)), m_exitCode(0)
{
QCoreApplication::setOrganizationName("ISIS");
QCoreApplication::setApplicationName("MantidPlot");
Expand Down Expand Up @@ -1593,6 +1593,28 @@ void ApplicationWindow::customColumnActions()
actionSwapColumns->setEnabled(true);
}


/** Set the exit code to be returned by the application at
* exit. Used by MantidPlot unit tests to signal failure.
*
* @param code :: int code, non-zero for failure
*/
void ApplicationWindow::setExitCode(int code)
{
m_exitCode = code;
}

/** Get the exit code to be returned by the application at
* exit. Used by MantidPlot unit tests to signal failure.
*
* @return code :: int code, non-zero for failure
*/
int ApplicationWindow::getExitCode()
{
return m_exitCode;
}


void ApplicationWindow::customToolBars(MdiSubWindow* w)
{
disableToolbars();
Expand Down
6 changes: 6 additions & 0 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ class ApplicationWindow: public QMainWindow, public Scripted
const QList<QMenu*> & getCustomMenus() const; //Mantid
ScriptingWindow* getScriptWindowHandle() { return scriptingWindow; }
bool getMenuSettingsFlag(const QString & menu_item);

void setExitCode(int code);
int getExitCode();
//-------------------
//@}

Expand Down Expand Up @@ -1411,6 +1414,9 @@ public slots:
/// Store a list of environments that cannot be used
QSet<QString> m_bad_script_envs;

/// Exit code to set at application end
int m_exitCode;

public:
MantidUI *mantidUI;
};
Expand Down
4 changes: 3 additions & 1 deletion Code/Mantid/MantidPlot/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ int main( int argc, char ** argv )
splash.finish(mw);

app.connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
return app.exec();
app.exec();
// Return the exit code (for MantidPlot unit tests)
return mw->getExitCode();
}
catch(std::exception& e)
{
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/MantidPlot/src/qti.sip
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,8 @@ sipClass=sipFindClass(sipCpp->className());
%End

public:
void setExitCode(int code);

enum MatrixToTableConversion{Direct, XYZ, YXZ};
Table* table(const QString&);
%MethodCode
Expand Down
8 changes: 5 additions & 3 deletions Code/Mantid/MantidPlot/test/MantidPlotSliceViewerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
This will test the interface to SliceViewer widgets.
Note: the SliceViewerPythonInterfaceTest.py offers
more tests of specific functions. Might be merged together with
this in the future?
more tests of specific functions. This module
tests (primarily) the plotSlice() helper methods that is available
only within mantidplot.py
"""
import sys
import os
Expand Down Expand Up @@ -71,7 +72,7 @@ def test_getSliceViewer(self):
svw2 = getSliceViewer('uniform')
assert svw2 is not None
self.assertEqual(svw2.getSlicer().getWorkspaceName(), "uniform")

def test_getSliceViewer_failure(self):
""" Retrieving an open SliceViewer, cases where it fails """
self.assertRaises(Exception, getSliceViewer, 'nonexistent')
Expand All @@ -80,3 +81,4 @@ def test_getSliceViewer_failure(self):

# Run the unit tests
mantidplottests.runTests(MantidPlotSliceViewerTest)

12 changes: 11 additions & 1 deletion Code/Mantid/MantidPlot/test/mantidplottests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import unittest
import time
import qti

def runTests(classname):
""" Run the test suite in the class.
Expand All @@ -22,5 +23,14 @@ def runTests(classname):
sys.path.append( os.path.join(src, "TestingTools/unittest-xml-reporting/src") )
import xmlrunner
runner = xmlrunner.XMLTestRunner(output='Testing')

#Run using either runner
runner.run(suite)
res = runner.run(suite)

# Set Mantid exit code
if not res.wasSuccessful():
qti.app.setExitCode(1)
else:
qti.app.setExitCode(0)

return res

0 comments on commit 23fa76a

Please sign in to comment.