Skip to content

Commit

Permalink
Refs #9129. Test for the error message
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbekasov committed Mar 11, 2014
1 parent 2eda20c commit 90e6723
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Code/Mantid/Framework/API/test/AlgorithmTest.h
Expand Up @@ -109,6 +109,42 @@ class AlgorithmWithValidateInputs : public Algorithm
};
DECLARE_ALGORITHM(AlgorithmWithValidateInputs)

/**
* Algorithm which fails on specified workspace
*/
class FailingAlgorithm : public Algorithm
{
public:
FailingAlgorithm() : Algorithm() {}
virtual ~FailingAlgorithm() {}
const std::string name() const { return "FailingAlgorithm"; }
int version() const { return 1; }

static const std::string FAIL_MSG;

void init()
{
declareProperty(new WorkspaceProperty<>("InputWorkspace","",Direction::Input));
declareProperty("WsNameToFail", "");
}

void exec()
{
std::string wsNameToFail = getPropertyValue("WsNameToFail");
std::string wsName = getPropertyValue("InputWorkspace");

std::cerr << wsNameToFail << wsName << std::endl;

if ( wsName == wsNameToFail )
{
throw std::runtime_error(FAIL_MSG);
}
}
};

const std::string FailingAlgorithm::FAIL_MSG("Algorithm failed as requested");

DECLARE_ALGORITHM(FailingAlgorithm)

class AlgorithmTest : public CxxTest::TestSuite
{
Expand Down Expand Up @@ -699,7 +735,30 @@ class AlgorithmTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS( ws1->readY(0)[0], 234 );
}

void test_processGroups_failsOnOneOfGroupWorkspaces()
{
makeWorkspaceGroup("A", "A_1,A_2,A_3");

FailingAlgorithm alg;
alg.initialize();
alg.setRethrows(true);
alg.setLogging(false);
alg.setPropertyValue("InputWorkspace", "A");
alg.setPropertyValue("WsNameToFail", "A_2");

try
{
alg.execute();
TS_FAIL("Exception wasn't thrown");
}
catch(std::runtime_error& e)
{
std::string msg(e.what());

TSM_ASSERT("Error message should contain original error",
msg.find(FailingAlgorithm::FAIL_MSG) != std::string::npos);
}
}

private:
IAlgorithm_sptr runFromString(const std::string & input)
Expand Down

0 comments on commit 90e6723

Please sign in to comment.