Xcode unit test compile-time error in Swift -
swift's advanced type-checking has ushered entire coding practice of maximizing compile-time type-checking.
a lot has been said traditional unit-testing vs. type-safety in code. find myself on type-safety side of equation, i.e., i've been trying make code raise many compile-time errors possible when used incorrectly.
however i'm wondering if there's way unit-test type-safety itself.
of course, type-safety errors exhibited compile-time errors. therefore, boils down unit-testing compile-time errors.
there answer achieving make in c++: unit test compile-time error
ideally, able following:
struct username: stringish{ ... } struct sqlquery: stringish{ ... } ... xctassertuncompilable{ func foo(a: username, b: sqlquery) { ... if (a == b) { ... } // error: cannot compare type username type sqlquery } xctassertuncompilable{ let user1 = username("joe") let selectallusers = sqlquery("select * users") user1 == selectallusers // error: cannot compare type username type sqlquery }
this bit more can hacked without serious support xcode-side.
so next best thing have similar solution presented in link before, i.e. separate script can test whether or not specific files can compile. of course, have able import proper frameworks/packages.
i'd happy idea of how make such script ios-swift without of hassle.
bonus points if can automatically called during usual testing phase of xcode. bonus points if "real" testing passes if external script passes.
Comments
Post a Comment