nomad-software / dunit Goto Github PK
View Code? Open in Web Editor NEWAdvanced unit testing toolkit for the D programming language
License: MIT License
Advanced unit testing toolkit for the D programming language
License: MIT License
I trying to compile with dmd v2.063.2, dub v0.9.18 on windows7 32-bit
Output:
D:\1310\mtk> dub --build=unittest
Checking dependencies in 'D:\1310\mtk'
The following changes will be performed:
Install dunit >=1.0.0, userWide
Downloading dunit 1.0.0...
Installing dunit 1.0.0 to C:\Users\volt\AppData\Roaming\dub\packages\...
dunit has been installed with version 1.0.0
Building configuration "application", build type unittest
Running dmd (compile)...
C:\...\dunit-1.0.0\source\dunit\toolkit.d(41): Error: constructor dunit.error.DUnitAssertError.this (string message, string file, uint line) is not callable using argument types (string, string, ulong)
C:\...\dunit-1.0.0\source\dunit\toolkit.d(41): Error: no constructor for DUnitAssertError
C:\...\dunit-1.0.0\source\dunit\error.d(108): Error: template instance dunit.toolkit.assertEqual!(string, string) error instantiating C:\Users\volt\AppData\Roaming\dub\packages\dunit-1.0.0\source\dunit\toolkit.d(41): Error: constructor dunit.error.DUnitAssertError.this (string message, string file, uint line) is not callable using argument types (string, string, ulong)
C:\...\dunit-1.0.0\source\dunit\toolkit.d(41): Error: no constructor for DUnitAssertError
C:\...\dunit-1.0.0\source\dunit\error.d(110): Error: template instance dunit.toolkit.assertEqual!(uint, int) error instantiating
C:\...\dunit-1.0.0\source\dunit\toolkit.d(41): Error: constructor dunit.error.DUnitAssertError.this (string message, string file, uint line) is not callable using argument types (string, string, ulong)
C:\...\dunit-1.0.0\source\dunit\toolkit.d(41): Error: no constructor for DUnitAssertError
C:\...\dunit-1.0.0\source\dunit\error.d(111): Error: template instance dunit.toolkit.assertEqual!(string[], string[]) error instantiating
C:\...\dunit-1.0.0\source\dunit\toolkit.d(207): Error: constructor dunit.error.DUnitAssertError.this (string message, string file, uint line) is not callable using argument types (string, string, ulong)
C:\...\dunit-1.0.0\source\dunit\toolkit.d(207): Error: no constructor for DUnitAssertError
C:\...\dunit-1.0.0\source\dunit\result.d(76): Error: template instance dunit.toolkit.assertEmpty!(DUnitAssertError[string]) error instantiating
C:\...\dunit-1.0.0\source\dunit\toolkit.d(387): Error: constructor dunit.error.DUnitAssertError.this (string message, string file, uint line) is not callable using argument types (string, string, ulong)
C:\...\dunit-1.0.0\source\dunit\toolkit.d(387): Error: no constructor for DUnitAssertError
C:\...\dunit-1.0.0\source\dunit\toolkit.d(316): Error: template instance dunit.toolkit.assertType!(bool, bool) error instantiating
C:\...\dunit-1.0.0\source\dunit\result.d(79): instantiated from here: assertTrue!(bool)
C:\...\dunit-1.0.0\source\dunit\toolkit.d(320): Error: constructor dunit.error.DUnitAssertError.this (string message, string file, uint line) is not callable using argument types (string, string, ulong)
C:\...\dunit-1.0.0\source\dunit\toolkit.d(320): Error: no constructor for DUnitAssertError
C:\...\dunit-1.0.0\source\dunit\result.d(79): Error: template instance dunit.toolkit.assertTrue!(bool) error instantiating
C:\...\dunit-1.0.0\source\dunit\toolkit.d(250): Error: constructor dunit.error.DUnitAssertError.this (string message, string file, uint line) is not callable using argument types (string, string, ulong)
C:\...\dunit-1.0.0\source\dunit\toolkit.d(250): Error: no constructor for DUnitAssertError
C:\...\dunit-1.0.0\source\dunit\result.d(82): Error: template instance dunit.toolkit.assertFalse!(bool) error instantiating
Error: Build command failed with exit code 1
For versions "1.0.0-beta" and "~master" output is same.
Using Dunit is great, but I just like things to be pretty.
I made a few changes, such as calculating the length of the lines, and printing a message to the Terminal titlebar.
I used ConsoleD, simply by versioning it off for my own use,
If I created a pull request to add optional color output, would it be considered?
Thanks!
Hey there,
Anyway we can get your library to support float comparisons?
+----------------------------------------------------------------------
| Failed asserting equal
+----------------------------------------------------------------------
| File: source/render/camera.d
| Line: 145
+----------------------------------------------------------------------
| ✓ Expected value: (float) 1.3
| ✗ Actual value: (float) 1.3
To test a class I usually inject mock interfaces without creating the concrete dependencies:
import dunit.mockable;
import std.algorithm;
interface IPerson {
string getSurname();
mixin Mockable!(IPerson);
}
class Processor() {
private IPerson person;
this(IPerson p) {
assert(p != null);
person = p;
}
string getName() {
return "Mr " ~ person.getSurname();
}
}
unittest {
import dunit.toolkit;
auto homer = IPerson.getMock();
homer.mockMethod("getSurname", delegate() { return "Simpson";} , 1, 1);
// I can test Processor without a concrete Person class
auto dec = new Processor(o);
assert(dec.getName() == "Mr Simpson");
homer.assertMethodCalls();
}
Do you plan to add mixin Mockable!(IPerson);
?
Thank you
please consider updating your .travis.yml
to ensure that the project will work with various os/compiler combinations.
language: d
sudo: required
dist: trusty
d:
- dmd
- dmd-2.069.2
- ldc
- gdc
os:
- linux
- osx
for some time I've found dunit unusable. with my current dmd install (2.080.1) on Windows I can't run dub test
with dunit in my project as it causes a linker error.
I modified source/example.d in this way
$git diff
diff --git a/source/example.d b/source/example.d
- processor.getAmountOfPeople().assertEqual(2);
+ processor.getAmountOfPeople().assertEqual(3);
then compile:
dmd -main -unittest example.d ../libdunit.a -ofexample -I.
./example
output is:
[email protected](91): Failed asserting equal
----------------
./e(void example.__unittestL62_3()+0x194) [0x492ad4]
./e(void example.__modtest()+0x9) [0x4b9851]
./e(int core.runtime.runModuleUnitTests().__foreachbody3(ref object.ModuleInfo*)+0x30) [0x4d613c]
./e(int rt.minfo.moduleinfos_apply(scope int delegate(ref object.ModuleInfo*)).__foreachbody2(ref rt.sections_linux.DSO)+0x4c) [0x4ca778]
./e(int rt.sections_linux.DSO.opApply(scope int delegate(ref rt.sections_linux.DSO))+0x42) [0x4ca7ee]
./e(int rt.minfo.moduleinfos_apply(scope int delegate(ref object.ModuleInfo*))+0x25) [0x4ca711]
./e(runModuleUnitTests+0xae) [0x4d5fd2]
./e(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()+0x17) [0x4c82c3]
./e(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x2a) [0x4c8276]
./e(_d_run_main+0x1a3) [0x4c81f7]
./e(main+0x17) [0x4b98df]
/usr/lib/libc.so.6(__libc_start_main+0xf5) [0x7fcb86c7abc5]
dmd version
dmd --help
DMD64 D Compiler v2.064
Hello! I really like your framework, and I'd like to use it in my project. However, I can't seem to make it work correctly -- the nice, human-readable output of failed tests don't work.
I've created a minimal project with dub init
, and then copied the exaple.d
into the source
directory. Then, I've changed some values in a test to make it fail. Here's the output I get:
➜ test tree
.
├── dub.json
├── source
│ ├── app.d
│ └── example.d
➜ test dub test
Generating test runner configuration '__test__library__' for 'library' (library).
Performing "unittest" build using dmd for x86_64.
dunit 1.0.14: target for configuration "library" is up to date.
teststuff ~master: building configuration "__test__library__"...
Linking...
To force a rebuild of up-to-date targets, run again with --force.
Running ./__test__library__
dunit.error.DUnitAssertError@source/example.d(92): Failed asserting equal
----------------
../../.dub/packages/dunit-1.0.14/dunit/source/dunit/toolkit.d:391 pure @safe void dunit.toolkit.assertEqual!(ulong, int).assertEqual(ulong, int, immutable(char)[], immutable(char)[], ulong) [0x484db5]
source/example.d:69 void example.__unittestL63_4() [0x462186]
??:? void example.__modtest() [0x488098]
??:? int core.runtime.runModuleUnitTests().__foreachbody2(object.ModuleInfo*) [0x4a505c]
??:? int object.ModuleInfo.opApply(scope int delegate(object.ModuleInfo*)).__lambda2(immutable(object.ModuleInfo*)) [0x48f88e]
??:? int rt.minfo.moduleinfos_apply(scope int delegate(immutable(object.ModuleInfo*))).__foreachbody2(ref rt.sections_elf_shared.DSO) [0x496cdd]
??:? int rt.sections_elf_shared.DSO.opApply(scope int delegate(ref rt.sections_elf_shared.DSO)) [0x496d6d]
??:? int rt.minfo.moduleinfos_apply(scope int delegate(immutable(object.ModuleInfo*))) [0x496c69]
??:? int object.ModuleInfo.opApply(scope int delegate(object.ModuleInfo*)) [0x48f865]
??:? runModuleUnitTests [0x4a4f3c]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [0x491e1e]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x491dbb]
??:? _d_run_main [0x491d1f]
??:? main [0x461ca1]
??:? __libc_start_main [0x9e38782f]
Program exited with code 1
I use dub version 1.0.0, and dunit version 1.0.14.
Any help is much appreciated!
I'm writing a library which needs to have @safe @nogc pure nothrow
API. To ensure this, I annotate my unittests with those attributes, however this currently means that I can't use dunit.toolkit
in those unittests.
Example:
module foo;
import dunit.mockable;
interface Foo {
mixin Mockable!Foo;
void foo() const;
}
unittest {
auto mock = Foo.getMock();
}
This fails with dmd (v2.065):
.dub/packages/dunit-master/source/dunit/mockable.d(121): Error: class foo.Foo.Mockable!(Foo).Mock!(Foo).Mock interface function 'void foo() const' is not implemented
Without the "const" qualifier the example compiles.
Not sure what I'm doing wrong:
Running <rdmd -w -g --main -unittest /Users/dbdavidson/dev/open_source/dunit/source/example.d>
STDERR: /Users/dbdavidson/dev/open_source/dunit/source/example.d(67): Error: no property 'getMock' for type 'example.Person'
/Users/dbdavidson/dev/open_source/dunit/source/example.d(67): Error: Person is not an expression
STDERR: /Users/dbdavidson/dev/open_source/dunit/source/example.d(70): Error: no property 'getMock' for type 'example.Person'
/Users/dbdavidson/dev/open_source/dunit/source/example.d(70): Error: Person is not an expression
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.