>From 55da2a5184d19d61111ef30e7783c8a13637acf9 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin
Date: Sun, 26 Oct 2014 01:45:55 +0200
Subject: [PATCH 3/3] Skip the tests which can't work without the special
password.
Allow the possibility to skip the tests by throwing an exception of special
test_skipped_exception class, although currently it can only be done via a
wrapper skip_if_not_supported() helper function, that throws it if support for
the files of the given type is not enabled in the program.
Use this to skip create_open_* and validate_output_mec tests if necessary.
---
main_wx_test.cpp | 74 +++++++++++++++++++++++++++++++++++++-----
wx_test_case.hpp | 16 +++++++++
wx_test_create_open.cpp | 26 +++++++++------
wx_test_validate_output.cpp | 2 +
4 files changed, 99 insertions(+), 19 deletions(-)
diff --git a/main_wx_test.cpp b/main_wx_test.cpp
index d7a8f5b..c192993 100644
--- a/main_wx_test.cpp
+++ b/main_wx_test.cpp
@@ -37,6 +37,7 @@
#include "uncopyable_lmi.hpp"
#include "wx_test_case.hpp"
+#include
#include
#include
#include // wxEntry()
@@ -108,6 +109,20 @@ class test_assertion_failure_exception
}
};
+/// Exception thrown if the test needs to be skipped.
+///
+/// This exception doesn't carry any extra information but just needs to have a
+/// distinct type to allow treating it differently in run().
+class test_skipped_exception
+ :public stealth_exception
+{
+ public:
+ test_skipped_exception(std::string const& what)
+ :stealth_exception(what)
+ {
+ }
+};
+
/// Simple struct collecting the statistics about the tests we ran.
///
/// Implicitly-declared special member functions do the right thing.
@@ -115,11 +130,17 @@ struct TestsResults
{
TestsResults()
:total(0)
+ ,passed(0)
+ ,skipped(0)
,failed(0)
{
}
+ // The sum of passed, skipped and failed is the same as total (except when
+ // a test is in process of execution and its result is yet unknown).
int total,
+ passed,
+ skipped,
failed;
};
@@ -348,6 +369,12 @@ TestsResults application_test::run()
wxStopWatch sw;
i->run_test();
wxLogMessage("%s%s: ok (%ldms)", indent, i->get_name(), sw.Time());
+ results.passed++;
+ }
+ catch(test_skipped_exception const& e)
+ {
+ wxLogMessage("%s%s: skipped (%s)", indent, i->get_name(), e.what());
+ results.skipped++;
}
catch(std::exception const& e)
{
@@ -431,6 +458,20 @@ wx_base_test_case::wx_base_test_case(char const* name)
return application_test::instance().get_config_for(get_name());
}
+void wx_base_test_case::skip_if_not_supported(char const* file)
+{
+ const wxString p(file);
+ if(!wxDocManager::GetDocumentManager()->FindTemplateForPath(p))
+ {
+ throw test_skipped_exception
+ (wxString::Format
+ ("documents with extension \"%s\" not supported"
+ ,p.AfterLast('.')
+ ).ToStdString()
+ );
+ }
+}
+
// Application to drive the tests
class SkeletonTest : public Skeleton
{
@@ -589,24 +630,39 @@ void SkeletonTest::RunTheTests()
TestsResults const results = application_test::instance().run();
is_running_tests_ = false;
- if (results.total == 0)
+ if(results.failed == 0)
{
- wxLogMessage("WARNING: no tests have been executed.");
+ if(results.passed == 0)
+ {
+ wxLogMessage("WARNING: no tests have been executed.");
+ }
+ else
+ {
+ wxLogMessage
+ ("SUCCESS: %d test%s successfully completed in %ldms."
+ ,results.passed
+ ,results.passed == 1 ? "" : "s"
+ ,sw.Time()
+ );
+ }
}
- else if (results.failed == 0)
+ else
{
wxLogMessage
- ("SUCCESS: %d tests successfully completed in %ldms."
+ ("FAILURE: %d out of %d test%s failed."
+ ,results.failed
,results.total
- ,sw.Time()
+ ,results.total == 1 ? "" : "s"
);
}
- else
+
+ if(results.skipped)
{
wxLogMessage
- ("FAILURE: %d out of %d tests failed."
- ,results.failed
- ,results.total
+ ("(%s skipped)"
+ ,results.skipped == 1
+ ? wxString("1 test was")
+ : wxString::Format("%d tests were", results.skipped)
);
}
diff --git a/wx_test_case.hpp b/wx_test_case.hpp
index d6c0c82..e408a38 100644
--- a/wx_test_case.hpp
+++ b/wx_test_case.hpp
@@ -49,6 +49,22 @@ class wx_base_test_case
// dtor doesn't really need to be virtual.
virtual ~wx_base_test_case() { }
+ /// Skip the test if the specified file is not supported.
+ ///
+ /// Check if the possibility to open such files is provided by the program
+ /// in its current configuration: some file types are conditionally enabled
+ /// only if special command line arguments are provided, so it is normal
+ /// for them to not be available and this shouldn't result in the test
+ /// errors.
+ ///
+ /// Notice that this method needs to be public to be usable from helpers of
+ /// the tests and not just from the test code itself.
+ ///
+ /// The file doesn't need to exist, but must have the correct extension.
+ ///
+ /// Throws test_skipped_exception if the file is not supported.
+ void skip_if_not_supported(char const* file);
+
protected:
/// The argument must be a literal, as we just store the pointer.
explicit wx_base_test_case(char const* name);
diff --git a/wx_test_create_open.cpp b/wx_test_create_open.cpp
index 844a36a..8058123 100644
--- a/wx_test_create_open.cpp
+++ b/wx_test_create_open.cpp
@@ -46,8 +46,14 @@
// ready for this dialog appearing and, second, "File|Save" menu command is
// disabled for the files created in this way and "File|Save as" needs to
// be used instead.
-void do_test_create_open(int key, wxString const& file, bool uses_dialog)
+void do_test_create_open
+ (wx_base_test_case& test
+ ,int key
+ ,wxString const& file
+ ,bool uses_dialog)
{
+ test.skip_if_not_supported(file);
+
LMI_ASSERT(!wxFileExists(file));
wxUIActionSimulator z;
@@ -100,45 +106,45 @@ void do_test_create_open(int key, wxString const& file, bool uses_dialog)
LMI_WX_TEST_CASE(create_open_census)
{
- do_test_create_open('c', "testfile.cns", false);
+ do_test_create_open(*this, 'c', "testfile.cns", false);
}
LMI_WX_TEST_CASE(create_open_illustration)
{
- do_test_create_open('i', "testfile.ill", true);
+ do_test_create_open(*this, 'i', "testfile.ill", true);
}
LMI_WX_TEST_CASE(create_open_database)
{
- do_test_create_open('d', "testfile.database", false);
+ do_test_create_open(*this, 'd', "testfile.database", false);
}
LMI_WX_TEST_CASE(create_open_policy)
{
- do_test_create_open('p', "testfile.policy", false);
+ do_test_create_open(*this, 'p', "testfile.policy", false);
}
LMI_WX_TEST_CASE(create_open_rounding)
{
- do_test_create_open('r', "testfile.rounding", false);
+ do_test_create_open(*this, 'r', "testfile.rounding", false);
}
LMI_WX_TEST_CASE(create_open_strata)
{
- do_test_create_open('s', "testfile.strata", false);
+ do_test_create_open(*this, 's', "testfile.strata", false);
}
LMI_WX_TEST_CASE(create_open_mec)
{
- do_test_create_open('m', "testfile.mec", true);
+ do_test_create_open(*this, 'm', "testfile.mec", true);
}
LMI_WX_TEST_CASE(create_open_gpt)
{
- do_test_create_open('g', "testfile.gpt", true);
+ do_test_create_open(*this, 'g', "testfile.gpt", true);
}
LMI_WX_TEST_CASE(create_open_text)
{
- do_test_create_open('x', "testfile.txt", false);
+ do_test_create_open(*this, 'x', "testfile.txt", false);
}
diff --git a/wx_test_validate_output.cpp b/wx_test_validate_output.cpp
index ceaa532..a73c9df 100644
--- a/wx_test_validate_output.cpp
+++ b/wx_test_validate_output.cpp
@@ -153,6 +153,8 @@ class output_file_existence_checker
LMI_WX_TEST_CASE(validate_output_mec)
{
+ skip_if_not_supported("unnamed.mec");
+
std::string const&
ext = configurable_settings::instance().spreadsheet_file_extension();
--
1.7.9