原文
通常在独立单元测试
上工作,因为速度
和更少输出
,只想运行
一个.而通常在文件中有几个单元测试
.急需要命名
单元测试.
只需要,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