Tests for GSI kwargs, test framework enhanced to print the total number of tests

This commit is contained in:
Matthias Koefferlein 2023-12-28 19:44:44 +01:00
parent f685fe3adf
commit e2ba78185c
4 changed files with 134 additions and 13 deletions

View File

@ -651,4 +651,124 @@ TEST(12)
EXPECT_EQ (v.to_string (), std::string ("r0 *1 1,2"));
v = e.parse ("var t = CplxTrans.new(mag=1.5)").execute ();
EXPECT_EQ (v.to_string (), std::string ("r0 *1.5 0,0"));
v = e.parse ("var t = CplxTrans.new(1.5, 45, true, 1, 2)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m22.5 *1.5 1,2"));
v = e.parse ("var t = CplxTrans.new(1.5, 45, true, DVector.new(1, 2))").execute ();
EXPECT_EQ (v.to_string (), std::string ("m22.5 *1.5 1,2"));
v = e.parse ("var t = CplxTrans.new(1.5, x=1, y=2, mirrx=true, rot=45)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m22.5 *1.5 1,2"));
v = e.parse ("var t = CplxTrans.new(CplxTrans.M0)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 *1 0,0"));
v = e.parse ("var t = CplxTrans.new(CplxTrans.M0, u=DVector.new(1, 2))").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 *1 1,2"));
v = e.parse ("var t = CplxTrans.new(CplxTrans.M0, mag=1.5, u=DVector.new(1, 2))").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 *1.5 1,2"));
v = e.parse ("var t = CplxTrans.new(CplxTrans.M0, 1.5, DVector.new(1, 2))").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 *1.5 1,2"));
v = e.parse ("var t = CplxTrans.new(CplxTrans.M0, mag=1.5, x=1, y=2)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 *1.5 1,2"));
v = e.parse ("var t = CplxTrans.new(CplxTrans.M0, 1.5, 1, 2)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 *1.5 1,2"));
v = e.parse ("var t = CplxTrans.new(VCplxTrans.M0)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 *1 0,0"));
v = e.parse ("var t = CplxTrans.new(ICplxTrans.M0)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 *1 0,0"));
v = e.parse ("var t = CplxTrans.new(DCplxTrans.M0)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 *1 0,0"));
v = e.parse ("var t = CplxTrans.new(Trans.M0)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 *1 0,0"));
v = e.parse ("var t = CplxTrans.new(Trans.M0, 1.5)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 *1.5 0,0"));
v = e.parse ("var t = CplxTrans.new(Trans.M0, mag=1.5)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 *1.5 0,0"));
v = e.parse ("var t = CplxTrans.new(t = Trans.M0, mag=1.5)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 *1.5 0,0"));
v = e.parse ("var t = CplxTrans.new(); t.disp=[1,2]; t").execute ();
EXPECT_EQ (v.to_string (), std::string ("r0 *1 1,2"));
v = e.parse ("var t = ICplxTrans.new(15, 25); t.to_s(dbu=0.01)").execute ();
EXPECT_EQ (v.to_string (), std::string ("r0 *1 0.15000,0.25000"));
}
TEST(13)
{
// Keyword arguments are best tested on transformations, here Trans
tl::Eval e;
tl::Variant v;
v = e.parse ("var t = Trans.new(Trans.M0, 1, 2)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 1,2"));
v = e.parse ("var t = Trans.new(Trans.M0, x = 1, y = 2)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 1,2"));
v = e.parse ("var t = Trans.new(Trans.M0, Vector.new(1, 2))").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 1,2"));
v = e.parse ("var t = Trans.new(Trans.M0, u=Vector.new(1, 2))").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 1,2"));
v = e.parse ("var t = Trans.new(rot=3, mirrx=true)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m135 0,0"));
v = e.parse ("var t = Trans.new(rot=3, mirrx=true, x=1, y=2)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m135 1,2"));
v = e.parse ("var t = Trans.new(3, true, 1, 2)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m135 1,2"));
v = e.parse ("var t = Trans.new(3, true, Vector.new(1, 2))").execute ();
EXPECT_EQ (v.to_string (), std::string ("m135 1,2"));
v = e.parse ("var t = Trans.new(rot=3, mirrx=true, u=Vector.new(1, 2))").execute ();
EXPECT_EQ (v.to_string (), std::string ("m135 1,2"));
v = e.parse ("var t = Trans.new()").execute ();
EXPECT_EQ (v.to_string (), std::string ("r0 0,0"));
v = e.parse ("var t = Trans.new(DTrans.M0)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 0,0"));
v = e.parse ("var t = Trans.new(DTrans.M0, 1, 2)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 1,2"));
v = e.parse ("var t = Trans.new(DTrans.M0, x=1, y=2)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 1,2"));
v = e.parse ("var t = Trans.new(c = DTrans.M0, x=1, y=2)").execute ();
EXPECT_EQ (v.to_string (), std::string ("m0 1,2"));
v = e.parse ("var t = Trans.new(Vector.new(1, 2))").execute ();
EXPECT_EQ (v.to_string (), std::string ("r0 1,2"));
v = e.parse ("var t = Trans.new(1, 2)").execute ();
EXPECT_EQ (v.to_string (), std::string ("r0 1,2"));
}
TEST(14)
{
// Keyword arguments and errors
tl::Eval e;
tl::Variant v;
try {
v = e.parse("var t = CplxTrans.new(1.5, 2.5); t.to_s(dbu='abc')").execute();
EXPECT_EQ (true, false);
} catch (tl::Exception &ex) {
EXPECT_EQ (ex.msg (), "Unexpected text after numeric value: '...abc' (argument 'dbu') at position 34 (...to_s(dbu='abc'))");
}
try {
v = e.parse("var t = CplxTrans.new(1.5, 2.5); var tt = CplxTrans.new(); t.assign(other=t)").execute();
EXPECT_EQ (true, false);
} catch (tl::Exception &ex) {
EXPECT_EQ (ex.msg ().find ("Keyword arguments not permitted at position 60 (...assign(other=t))"), 0);
}
try {
v = e.parse("var t = CplxTrans.new('abc');").execute();
EXPECT_EQ (true, false);
} catch (tl::Exception &ex) {
EXPECT_EQ (ex.msg ().find ("No overload with matching arguments. Variants are:"), 0);
}
try {
v = e.parse("var t = CplxTrans.new(uu=17);").execute();
EXPECT_EQ (true, false);
} catch (tl::Exception &ex) {
EXPECT_EQ (ex.msg ().find ("Can't match arguments. Variants are:"), 0);
}
try {
v = e.parse("var t = CplxTrans.new(u='17');").execute();
EXPECT_EQ (true, false);
} catch (tl::Exception &ex) {
EXPECT_EQ (ex.msg ().find ("No overload with matching arguments. Variants are:"), 0);
}
}

View File

@ -222,6 +222,7 @@ run_tests (const std::vector<tl::TestBase *> &selected_tests, bool editable, boo
std::vector <tl::TestBase *> failed_tests_e, failed_tests_ne;
int skipped_ne = 0, skipped_e = 0;
std::vector <tl::TestBase *> skipped_tests_e, skipped_tests_ne;
int successful_ne = 0, successful_e = 0;
for (int e = 0; e < 2; ++e) {
@ -242,6 +243,7 @@ run_tests (const std::vector<tl::TestBase *> &selected_tests, bool editable, boo
std::vector <tl::TestBase *> failed_tests;
int skipped = 0;
std::vector <tl::TestBase *> skipped_tests;
int successful = 0;
tl::Timer timer;
@ -292,6 +294,8 @@ run_tests (const std::vector<tl::TestBase *> &selected_tests, bool editable, boo
ut::noctrl << "Memory: " << timer.memory_size () / 1024 << "k";
ut::ctrl << "<x-testcase-times wall=\"" << timer.sec_wall () << "\" user=\"" << timer.sec_user () << "\" sys=\"" << timer.sec_sys () << "\" memory=\"" << timer.memory_size () << "\"/>";
++successful;
} catch (tl::CancelException &) {
ut::ctrl << "</system-out>";
@ -335,6 +339,8 @@ run_tests (const std::vector<tl::TestBase *> &selected_tests, bool editable, boo
ut::noctrl << tl::replicate ("=", ut::TestConsole::instance ()->real_columns ());
ut::noctrl << "Summary";
tl::info << "Executed " << (successful + failed) << " test(s) in " << mode << " mode.";
if (skipped > 0) {
if (e == 0) {
skipped_tests_ne = skipped_tests;
@ -359,6 +365,12 @@ run_tests (const std::vector<tl::TestBase *> &selected_tests, bool editable, boo
tl::info << "All tests passed in " << mode << " mode.";
}
if (e == 0) {
successful_ne = successful;
} else {
successful_e = successful;
}
ut::ctrl << "</x-summary>";
ut::noctrl << "Total time: " << timer.sec_wall () << "s (wall) " << timer.sec_user () << "s (user) " << timer.sec_sys () << "s (sys)";
@ -421,6 +433,8 @@ run_tests (const std::vector<tl::TestBase *> &selected_tests, bool editable, boo
ut::ctrl << "<x-grand-summary>";
tl::info << "Executed " << (successful_e + failed_e + successful_ne + failed_ne) << " test(s)";
if (skipped_e + skipped_ne > 0) {
if (non_editable) {
tl::warn << "Skipped in non-editable mode";

View File

@ -198,12 +198,6 @@ class KWArgsTest(unittest.TestCase):
except Exception as ex:
self.assertEqual(str(ex).find("No overload with matching arguments."), 0)
try:
t = pya.Trans("17")
self.assertEqual(True, False)
except Exception as ex:
self.assertEqual(str(ex).find("No overload with matching arguments."), 0)
# run unit tests
if __name__ == '__main__':

View File

@ -210,13 +210,6 @@ class KWArgs_TestClass < TestBase
assert_equal(ex.to_s.index("No overload with matching arguments."), 0)
end
begin
t = RBA::Trans::new("17")
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s.index("No overload with matching arguments."), 0)
end
end
end