Which tools do you miss in D?
Gary Willoughby
dev at nomad.so
Mon Jan 27 02:26:13 PST 2014
On Monday, 27 January 2014 at 07:16:26 UTC, Knud Soerensen wrote:
> I miss check_expect from racket.
>
> It is used for unit testing
>
> check_expect(expression, result)
> Will test if expression equals result
> if it is not it print "Got expression but expected result" with
> file and
> line information.
>
> In D making unit tests is more tedious.
> When I develop in D I typical start with.
>
> writeln(expression)
> writeln(result)
>
> then when the code is working I replace it with
> assert(expression==result)
>
> Then if I do some refactoring which don't work I change again
> writeln(expression)
> writeln(result)
>
> When it is working again
> assert(expression==result)
>
> This back and forth process in D is very tedious compared to
> Racket.
>
> I think the should be a buildin function called test or
> something
> for-filing the same role as check_expect in racket.
>
> Knud
>
> On 2014-01-26 21:29, Oten wrote:
>> Which tools do you miss in the D language? it can be from any
>> language not from C or C++ only but from any language that you
>> have used and liked (might not liked but increased productivity
>> anyway) A very common argument from peoples which do choose
>> other language than D is lack of your tools for D, even if they
>> want to get D they say can't switch. The most common tools
>> which
>> they miss is debuggers/static analyzer/lint and so on. I think
>> that by sharing this list with community instead of just say it
>> like a criticizes is good because next time that some people
>> say
>> that such a x tools isn't available you can say "No, there's a
>> D
>> version for that". Also, totally new ideas are very welcome. If
>> you have had a idea that for any reason you wouldn't implement
>> yourself, tell us too.
>> (sorry for english, not my native language)
import std.stdio;
void check_expect(A, B)(lazy A expression, B result, string file
= __FILE__, size_t line = __LINE__)
{
try
{
if (expression != result)
{
throw new Exception("Got expression but expected result",
file, line);
}
}
catch (Exception ex)
{
writefln("%s, file: %s, line: %s", ex.msg, ex.file, ex.line);
}
}
unittest
{
check_expect(1 + 2, 4);
}
You can find more usesful functions for unit testing here:
https://github.com/nomad-software/dunit
More information about the Digitalmars-d
mailing list