![](/style/images/good.png)
4
![](/style/images/bad.png)
使用datefudge锁定测试时间
source link: https://www.lujun9972.win/blog/2019/08/31/%E4%BD%BF%E7%94%A8datefudge%E9%94%81%E5%AE%9A%E6%B5%8B%E8%AF%95%E6%97%B6%E9%97%B4/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
使用datefudge锁定测试时间
有些测试跟时间有关,比如当我想测试Emacs Org Agenda方面配置的内容时就跟当前时间有很大关系。
这类测试很麻烦,因为你的测试结果会随着时间的流逝而改变,这导致几乎无法进行自动测试。
今天突然发现 datefudge
这个工具,可以帮助解决这个问题
datefudge is a small utility that pretends that the system time is different by preloading a small library which modifies the time(2), gettimeofday(2) and clock_gettime(2) system calls.
它的用法很假单
datefudge [-s|--static] 模拟的时间 运行的命令
这样在命令运行时获取到的时间就会是指定的时间了,比如
datefudge 20180810 date
Fri Aug 10 00:00:00 HKT 2018
其中 -s
或者 --static
则表示运行的命令每次获取的时间都不变,比如的例子很容易看出区别
datefudge 20180810 bash -c "date;sleep 2;date" echo --------------------------- datefudge -s 20180810 bash -c "date;sleep 1;date"
Fri Aug 10 00:00:00 HKT 2018 Fri Aug 10 00:00:02 HKT 2018 --------------------------- Fri Aug 10 00:00:00 HKT 2018 Fri Aug 10 00:00:00 HKT 2018
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK