- 浏览: 229896 次
- 性别:
- 来自: 昆明
文章分类
最新评论
-
beiyangshuishi:
确实挺幽默的,太能恶搞了。不过这也让我想起日本的一则广告宣纸的 ...
一对活宝—— MySQL & PostgreSQL -
ShiningRay:
稍微看了vcf的api,比wxwidgets要干净得多
VCF 库的搞笑提示 -
Colorful:
Wow, this is amazing.
D语言 struct constrcutor 的 bug -
oldrev:
楼下,当时的 TRAC 确实说是要 py 2.4 的
出色的开源项目管理软件——Redmine -
jusdao:
...Trac可以用python2.5啊,没有说必须用2.4的 ...
出色的开源项目管理软件——Redmine
一个模仿 Ruby Test::Unit 的 Quick & Dirty 单元测试框架,托 __traits 的福,看起来已经有那么点意思了。提取行号在目前还没法实现,估计等 macro 出来就能解决这个问题。
SVN里的最新版在下面的链接处:
dotmars.googlecode.com/svn/trunk/sandbox/2.0/test.d
D2.0 代码
运行结果
oldrev@ubuntu:~/work/dotmars/sandbox/2.0$ dmd2 -run test.d
Started...
Finished
Error: stest.MyTestCase.testOne
Exception raised
Failure: test.MyTestCase.testOne [test.MyTestCase]
A stupid assertion
Failure: test.MyTestCase2.testThree [test.MyTestCase2]
Yet another stupid assertion
7 tests, 9 assertions, 2 failures, 1 errors
Happy hacking!
SVN里的最新版在下面的链接处:
dotmars.googlecode.com/svn/trunk/sandbox/2.0/test.d
D2.0 代码
- /**
- A D 2.0 unit test framework inspired by Ruby's Unit::Test
- // Written in the D programming language 2.0
- Authors: Wei Li (oldrev@gmail.com)
- License: BSD
- Copyright: Copyright (C) 2007 by Wei Li.
- */
- import std.stdio;
- ////////////////////////////////////////////////////////////////////////////////
- struct Failure
- {
- string location;
- string message;
- string testName;
- }
- ////////////////////////////////////////////////////////////////////////////////
- struct Error
- {
- Exception exception;
- string testName;
- }
- ////////////////////////////////////////////////////////////////////////////////
- class TestResult
- {
- private Error[] m_errors;
- private Failure[] m_fails;
- private int m_runCount;
- private int m_assertionCount;
- private int m_testCount;
- const(Error)[] errors() {
- return m_errors;
- }
- const(Failure)[] failures() {
- return m_fails;
- }
- void addFailure(const string loc, const string msg, const string name)
- {
- Failure f;
- with(f) {
- location = loc;
- message = msg;
- testName = name;
- }
- m_fails ~= f;
- }
- void addError(Exception ex, const string name)
- {
- Error e;
- with(e) {
- exception = ex;
- testName = name;
- }
- m_errors ~= e;
- }
- void addAssertion() {
- m_assertionCount++;
- }
- void addTest() {
- m_testCount++;
- }
- void addRun() {
- m_runCount++;
- }
- bool hasPassed() {
- return m_errors.length == 0 && m_fails.length == 0;
- }
- int errorCount() {
- return cast(int)m_errors.length;
- }
- int failureCount() {
- return cast(int)m_fails.length;
- }
- int runCount() {
- return m_runCount;
- }
- int testCount() {
- return m_testCount;
- }
- int assertionCount() {
- return m_assertionCount;
- }
- }
- ////////////////////////////////////////////////////////////////////////////////
- abstract class TestBase
- {
- protected this() {
- }
- abstract void run(TestResult result);
- abstract const bool isRunning();
- }
- ////////////////////////////////////////////////////////////////////////////////
- abstract class TestCase(Subclass) : TestBase
- {
- alias typeof(this) SelfType;
- struct TestMethod
- {
- string name;
- void delegate() method;
- }
- public const string name = Subclass.classinfo.name;
- private TestResult m_result;
- private TestMethod[] m_methods;
- private size_t m_currentMethod;
- private bool m_isFailed;
- private bool m_running = false;
- this() {
- }
- private static const(string) ctfMakeString(T)()
- {
- string ret;
- foreach(str; __traits(allMembers, T)) {
- if(str[0..4] == "test")
- ret ~= `addTestMethod(TestMethod("` ~ str ~ `", &sc.` ~ str ~ `)); ` ~ "\n";
- }
- return ret;
- }
- private void initial(const Subclass sc) {
- mixin(ctfMakeString!(Subclass)());
- }
- void addTestMethod(TestMethod tm) {
- m_methods ~= tm;
- }
- static Subclass createChild() {
- auto o = new Subclass;
- o.initial(o);
- return o;
- }
- void setup() {}
- void teardown() {}
- override const bool isRunning() {
- return m_running;
- }
- override void run(TestResult result)
- {
- m_result = result;
- m_result.addRun();
- foreach(size_t i, TestMethod tm; m_methods)
- {
- m_isFailed = false;
- m_currentMethod = i;
- m_result.addTest();
- setup();
- m_running = true;
- try {
- tm.method();
- }
- catch(Exception ex) {
- m_result.addError(ex, currentMethodName);
- }
- finally {
- m_running = false;
- }
- teardown();
- }
- }
- const string currentMethodName() {
- return name ~ "." ~ m_methods[m_currentMethod].name;
- }
- private void addFailure(const string message = null)
- {
- if(!m_isFailed)
- {
- m_isFailed = true;
- m_result.addFailure(name, message, currentMethodName);
- }
- }
- //////////////////////////// Assertion Functions ///////////////////////////
- void assertTrue(bool x, const string message = null)
- {
- m_result.addAssertion();
- if(!x) {
- addFailure(message);
- }
- }
- void assertNull(T)(const T value, const string message = null)
- {
- m_result.addAssertion();
- if(value !is null) {
- addFailure(message);
- }
- }
- void assertNotNull(T)(const T value, const string message = null)
- {
- m_result.addAssertion();
- if(value is null) {
- addFailure(message);
- }
- }
- void assertEqual(T)(const T expected, const T actual, const string message = null)
- {
- m_result.addAssertion();
- if(expected != actual) {
- addFailure(message);
- }
- }
- void assertNotEqual(T)(const T expected, const T actual, const T delta, const string message = null)
- {
- m_result.addAssertion();
- if(expected == actual) {
- addFailure(message);
- }
- }
- void flunk(const string message = "Flunked")
- {
- m_result.addAssertion();
- addFailure(message);
- }
- }
- ////////////////////////////////////////////////////////////////////////////////
- class TestSuit(Subclass, Tests...) : TestBase
- {
- alias typeof(this) SelfType;
- public const string name = Subclass.classinfo.name;
- private TestBase[] m_tests;
- private bool m_running = false;
- this()
- {
- m_running = false;
- foreach(T; Tests)
- {
- T test = T.createChild();
- addTest(test);
- }
- }
- static Subclass createChild() {
- return new Subclass;
- }
- const(TestBase)[] tests() {
- return m_tests;
- }
- void addTest(TestBase tb)
- in {
- assert(tb !is null);
- }
- body {
- m_tests ~= tb;
- }
- const bool empty() {
- return Tests.length == 0;
- }
- override const bool isRunning() {
- return m_running;
- }
- override void run(TestResult result) {
- m_running = true;
- foreach(test; m_tests) {
- test.run(result);
- }
- m_running = false;
- }
- }
- static class ConsoleRunner
- {
- static void showFailures(TestResult tr)
- {
- foreach(fail; tr.failures)
- {
- writefln("Failure: %s [%s]", fail.testName, fail.location);
- writefln("%s", fail.message);
- writefln();
- }
- }
- static void showErrors(TestResult tr)
- {
- foreach(err; tr.errors)
- {
- writefln("Error: s", err.testName);
- writefln("%s", err.exception.msg);
- writefln();
- }
- }
- static void run(TestBase tb)
- {
- auto result = new TestResult;
- writefln("Started...");
- tb.run(result);
- writefln("Finished\n");
- showErrors(result);
- showFailures(result);
- writefln();
- writefln("%d tests, %d assertions, %d failures, %d errors",
- result.testCount, result.assertionCount, result.failureCount, result.errorCount);
- if(result.hasPassed)
- writefln("Everything is OK.");
- }
- }
- ////////////////////////////////////////////////////////////////////////////////
- class MyTestCase : TestCase!(MyTestCase)
- {
- void testOne() {
- assertTrue(false, "A stupid assertion");
- assertTrue(true);
- assertTrue(true);
- throw new Exception("Exception raised");
- }
- void testTwo() {
- assertTrue(true);
- }
- void testThree() {
- assertTrue(true);
- }
- }
- class MyTestCase2 : TestCase!(MyTestCase2)
- {
- void testOne() {
- assertTrue(true);
- }
- void testTwo() {
- assertTrue(true);
- }
- void testThree() {
- assertTrue(false, "Yet another stupid assertion");
- }
- }
- class MyTestCase3 : TestCase!(MyTestCase3)
- {
- void testMethod() {
- assertTrue(true);
- }
- }
- class MyTestSuit1: TestSuit!(MyTestSuit1, MyTestCase)
- {
- }
- class MyTestSuit2: TestSuit!(MyTestSuit2, MyTestCase2)
- {
- }
- class MyTestSuit3: TestSuit!(MyTestSuit3, MyTestSuit1, MyTestSuit2, MyTestCase3)
- {
- }
- void main()
- {
- auto ts = new MyTestSuit3;
- ConsoleRunner.run(ts);
- }
运行结果
Started...
Finished
Error: stest.MyTestCase.testOne
Exception raised
Failure: test.MyTestCase.testOne [test.MyTestCase]
A stupid assertion
Failure: test.MyTestCase2.testThree [test.MyTestCase2]
Yet another stupid assertion
7 tests, 9 assertions, 2 failures, 1 errors
Happy hacking!
评论
3 楼
xgene
2007-07-28
2 楼
oldrev
2007-07-28
1 楼
oldrev
2007-07-27
Ruby的文档太成问题了,Programming Ruby 也不是很清楚
发表评论
-
Tango 0.99.7 Dominik 今天放出
2008-07-25 12:16 1372详细的发布公告: http://www.dsource.org ... -
D新闻组里的天才代码
2008-03-30 21:26 3261超猛的代码,刚才逛新闻组刚看到的,随便记录一下。 出自: ... -
Ubuntu & D
2008-03-23 12:33 2381前几天 Ubuntu Linux 8.04 (Hardy) 刚 ... -
Dotmars.test 单元测试框架简介
2007-11-19 22:43 94D语言内置的 unittest关键字+assert 组成的单元 ... -
mixin 模拟多继承
2007-11-10 17:40 3652D1.0 代码 /** TupleMixin ... -
简单的 C to D 转换 Ruby 脚本
2007-10-24 22:06 4589今天晚上费了点脑筋写了一个简单的 C2D 转换脚本,大致实现了 ... -
D1.0代码模拟 __traits(hasMember, ...)
2007-10-08 23:12 5106通过1.0的代码完全模拟了 D 2.0 __traits(ha ... -
更好的C++——给C++使用者的D语言简介
2007-09-14 01:30 12211作为 C++ 狂热的粉丝, ... -
让D代码自己编译自己
2007-09-12 22:55 4750刚在 D语言的新闻组里看到了D模板&元编程顶尖高人 ... -
Dotmars 实例之:容器、迭代器与算法框架
2007-08-03 23:49 5670Dotmars 实例之:容器、迭代器与算法框架 这几天 Mr. ... -
D 2.0 Const/Final/Invariant 概念简介
2007-07-24 22:55 5419D 2.0 Const/Final/Invariant 概 ... -
DotMars 版 Hello World
2007-06-05 02:17 8182DotMars 已经具有初步的样子了,特别发帖庆祝。 Dot ... -
关联数组字面值+函数字面值=支持任意类型的 switch
2007-05-19 23:29 4506刚才写字符串格式化的由于要处理所有内置类型,而且只有 Type ... -
.Net/Java 风格格式化字符串
2007-05-18 22:51 3580基础类库的东西看起来容易做起来难,今天花时间实现了一点点 . ... -
修改版 juno.com.base
2007-04-20 00:28 4276dsource 上的 juno 是一个很不错的 Windows ... -
C#-like 的 DLL 封装
2007-04-16 23:19 4366一个类似 C# 的 DllImport 实现,用于“半”动态加 ... -
简单的D语言 VIM 缩写插件
2007-04-13 15:45 3442昨晚我写了一个非常简单的 VIM 的D语言缩写插件,希望能让用 ... -
双向链表模板类
2007-04-07 02:03 3017参考 STL 实现的 Quick & Dirty 双向 ... -
用Rant自动化D语言程序构建
2007-03-31 13:54 3186上回说到 Rank 这个 Ruby 世界最广泛使用的构建工具在 ... -
D语言通用 Rakefile
2007-03-31 00:21 2903在一个日文网站上发现的通用 Rakefile for GDCr ...
相关推荐
对 .net1.0框架dll .net2.0框架dll反编译,利用反射机制获取.
.NET 框架向全世界引入了可用来分析任何基于 .NET 的代码(无论它是单个类还是完整的程序集)的反射概念。反射还可以用来检索有关特定程序集中包含的各种类、方法和属性的信息。使用 .NET Reflector,你可以浏览程序...
.net应用程序配置文件,可以让.net2.0编译的应用程序优先用.net4.0的框架运行,从而能利用反射使用.net4.0下面的所有功能,对于.net2.0的程序的兼容性有提升
Visual Studio Team System 中的单元测试与Web测试 案例分析:基于.NET2.0的大型电子商务系统 五 Windows 应用(Windows Forms) 创建Windows应用程序 主要Windows控件与自定义控件 WinForm中的数据处理 多...
ASP.NET 2.0 中的代码隐藏和编译 ASP.NET 2.0 Language Swithcer and Theme Swicher 多语言转换和多样式主题转换 ASP.NET2.0 ObjectDataSource的使用详解(1) ASP.NET2.0 ObjectDataSource的使用详解(2) ...
LINQ:Language Integrated Query 语言集成查询,其本质是对ADO.NET结果集通过反射连同泛型特性转换成对象集,实现OR模型的转换(类似JAVA中Hibernate框架,.NET中的NHibernate),它完全是基于.NET 2.0 的框架。...
NUnit是一个.NET上的单元测试框架。NUnit 1.x主要是移植JUnit 3.8。从2.0版本开始,NUnit进行了重写和重新设计,使用Attributes代替特定的方法和相应的基类。 6. MyGeneration MyGeneration是一个功能很强大的代码...
NUnit是一个.NET上的单元测试框架。NUnit 1.x主要是移植JUnit 3.8。从2.0版本开始,NUnit进行了重写和重新设计,使用Attributes代替特定的方法和相应的基类。 6. MyGeneration MyGeneration是一个功能很强大的代码...
理论上可以大幅提升反射执行时间,在以前的版本中,实体赋值通过反射的后期绑定执行,效率相对来说比较低下,本次更新使用全新的基于Emit的快速反射框架,通过Emit编译委托的方式大幅加快反射速度,理论上可能有十倍以上的...
在我的项目里,代码生成可以说是无处不在,有的时候是为了取代反射改善运行效率,有的时候是为了更方便的编写程序,有的时候是为了自动单元测试...那你将是为了什么呢? 我贡献的内容属于基础框架,不关联业务逻辑...
集合框架 1.2 I/O 1.3 Socket 网络通信 1.4 注解 1.5 反射 1.6 线程基础 1.7 Java 8+( >= 11) 新特性 1,8 常见面试题剖析 2. JVM 2.0 自己编译 JDK 2.1 内存区域与OOM 2.1.1 运行时数据区域 2.1.2 2.2 垃圾收集器与...
理论上可以大幅提升反射执行时间,在以前的版本中,实体赋值通过反射的后期绑定执行,效率相对来说比较低下,本次更新使用全新的基于Emit的快速反射框架,通过Emit编译委托的方式大幅加快反射速度,理论上可能有十倍以上的...
如果一个密封类被指定为其它类的基类,则会发生编译时错误。 密封类不能同时为抽象类。 sealed 修饰符主要用于防止非有意的派生,但是它还能促使某些运行时优化。具体说来,由于密封类永远不会有任何派生类,所以对...
FrameWork [java] 结构,框架 ['freimwә:k] Generic [java] 泛型 [dʒi'nerik] goto (保留字) 跳转 heap n.堆 [hi:p] implements (关键字) 实现 ['implimәnt] import (关键字) 引入(进口,输入) Info n.信息 ...