0
点赞
收藏
分享

微信扫一扫

d命名单元测试


​​原文​​

通常在独立​​单元测试​​​上工作,因为​​速度​​​和​​更少输出​​​,只想​​运行​​​一个.而通常在文件中有几个​​单元测试​​​.急需要​​命名​​​单元测试.
只需要,​​​version(newFeature) unittest {}​​.

#! /usr/bin/env dub
/++ dub.sdl:
dflags "-preview=shortenedMethods"
configuration "release" {
targetType "executable"
}
configuration "unittest" {
targetType "library"
dependency "silly" version="~>1.1.1"
}
+/

int factorial(int n) => n <= 1 ? 1 : n * factorial(n - 1);

@("!5") unittest {
assert(factorial(5) == 120);
}

@("!0 and !1") unittest {
assert(factorial(0) == 1);
assert(factorial(1) == 1);
}

version (unittest) {
} else {
void main(string[] args) {
import std.conv :;
import std.stdio :;

writeln(args[1].to!int.factorial);
}
}
//用法:

$ ./fact.d 10
3628800
$ dub -q test --single fact.d
? fact !5
? fact !0 and !1

Summary: 2 passed, 0 failed in 0


举报

相关推荐

0 条评论