olegsych / simply Goto Github PK
View Code? Open in Web Editor NEWA small library that wants to help you write C++ when it grows up.
License: MIT License
A small library that wants to help you write C++ when it grows up.
License: MIT License
template <typename T> void assert::null(const T* actual);
template <typename T> void assert::not_null(const T* actual);
These will replace the Assert::IsNull
and Assert::IsNotNull
functions in VSTest. The main challenge as in #1, is creating a descriptive representation of T*
for the assertion failure message. In addition to that, including type name and physical address may be useful.
void assert::true(int actual);
void assert::false(int actual);
These are similar to standard true(bool)
and false(bool)
from #2, but for C-style Boolean values #define TRUE 1
and #define FALSE 0
. They will allow writing semantic assertions like
assert::true(FALSE)
instead of
assert::equal(TRUE, FALSE);
and include terms TRUE
and FALSE
in assertion messages instead of the literal 1
and 0
.
Replace asserts like this:
assert::not_null(dynamic_cast<foo*>(bar));
with semantic asserts like this:
foo* f = assert::dynamic_cast<foo*>(bar);
// more asserts on f;
I currently have to use Assert::IsTrue
to test equality of GUID
values, because they are not convertible to string.
Assert::IsTrue(clsid == __uuidof(factory));
For example
HRESULT result = check(foo->Bar());
if (result == S_OK)
// do OK stuff
else if (result == S_FALSE)
// do FALSE stuff
template<typename T> void assert::equal(const T& expected, const T& actual);
template<typename T> void assert::not_equal(const T& not_expected, const T& actual);
This will replace the Assert::AreEqual(const T&, const T&)
and Assert::AreNotEqual(const T&, const T&)
methods in VSTest and will provide better assertion failure messages. The main challenge is converting values of template type T
to string. VSTest asks you to provide a custom ToString
method:
namespace Microsoft { namespace VisualStudio { namespace CppUnitTestFramework
{
// User should provide a specialization of below ToString() template to use equality asserts in test code.
// std::wstring ToString(const Q& q) is used for converting type Q in user readable std::wstring value.
// Converted value is emitted in Assert failure message. Specialization for basic types has been provided below.
template <typename Q> static std::wstring ToString(const Q& q) { static_assert(false, "Test writer must define specialization of ToString<const Q& q> for your class "__FUNCSIG__"."); }
}}}
There has to be a better way. Things to consider:
ostream& operator<< (ostream& os, const T& value)
that could be used to write a value to a string streamto_string
and to_wstring
methods for a number of types are available in the STLis_equal
for c-style stringsis_equal
for numeric values to avoid having to specify type explicitlyAnother function for assert/type_name.h
:
template<class base_t, class derived_t> void assert::is_base_of<base_t, derived_t>();
Assertion failure message should include names of base_t
and derived_t
types.
To simplify implementation of equality operators in consuming types, for example
struct foo
{
com_ptr<bar> baz;
bool operator==(const foo& other)
{
return baz == other.baz;
}
}
instead of
buz.get() == other.baz.get();
The STL smart pointers in <memory>
support the following style of null checking
void foo (unique_ptr<int> bar)
{
if (bar)
{
// use bar
}
}
It would be nice to allow similar coding style for com_ptr
in addition to this
void foo (com_ptr<int> bar)
{
if (bar.get())
{
// use bar
}
}
I don't know exactly how the STL are implemented. This possibly requires implementing operator bool()
and operator !()
.
void assert::true(bool condition);
void assert::false(bool condition);
These will replace the Assert::IsTrue
and Assert::IsFalse
functions in VSTest
Another assert for assert/type_traits.h
:
template<typename actual_t> void assert::is_abstract<actual_t>();
Assertion message should include the actual type name.
A semantic assertion to replace low-level assertions for C++ strings:
std::string s;
Assert::AreEqual<size_t>(0, s.length());
and C strings:
char* s;
Assert::AreEqual<size_t>(0, strlen(s));
with clean, high-level
assert::empty(s);
which includes actual content of the string in the failure message in addition to the string length.
The new method should be defined in assert/string.h
and handle the generic C++ string classes and both char*
and wchar_t*
C++ strings, similar to the existing assert::find
method.
type_name
is implemented in the simply.utility
package and currently used only by the simply.assert
package. Without a package dependency, simply.assert
fails to build when installed without simply.utility
. It would be better to move the type_name
to implementation of simply.assert
where its used.
I use a lot of assertions like this:
Assert::AreEqual(E_INVALIDARG, sut->QueryInterface(IID_IUnknown, nullptr));
which produce meaningless assertion messages where HRESULT
values appear as large numbers. I'd like to get meaningful assertion messages that at the very least include names, like E_NOTIMPL
instead of their numeric values.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.