首页 文章 精选 留言 我的

精选列表

搜索[聚类],共10000篇文章
优秀的个人博客,低调大师

JavaScript 日期处理类库 Moment.js 进入维护状态

Moment团队宣布 Moment.js 已进入维护状态,后续不会再为其增加新功能,并建议新项目不要使用 Moment.js,推荐使用更现代的库或 JavaScript 目前的实验性提案Temporal。 根据官方提供的数据,Moment.js 已被成功用于数百万个项目,截至2020年9月,Moment.js 每周下载量超过 1200 万。但它毕竟是一个为 JavaScript 生态旧时代而构建的项目,近年来,虽然 Moment.js 有所发展,但其底层设计并没有改变,依旧与 2011 年创建时基本相同。这导致它未能很好适应现代开发,但如果要对它进行改造,工作量也比较大,而且目前已经有了更好的替代方案,所以团队决定让Moment.js 止步于此。 Moment.js 进入维护状态意味着: 团队不会再为其增加新功能 团队不会将其 API 更改为 immutable 团队不会解决 Tree-shaking 或捆绑包大小的问题 团队不会对其进行任何重大更改(没有大版本 Moment.js 3) 团队可能选择不修复错误或特异性的操作,特别是长期存在的已知问题 Moment团队表示他们知道许多已存在的项目可能会继续使用 Moment.js,所以 当出现严重的安全问题时,团队会予以解决 在IANA 时区数据库更新后,团队会为 Moment-Timezone 发布更新 虽然 Moment团队阻止未来的新项目使用 Moment.js,但如果有一些特殊情况依旧可以继续使用它,例如对浏览器支持有特别要求,因为 Moment.js 支持IE 8 及更高版本。如果项目中有其他库依赖Moment.js,并暂时找不到更好的替代方案,团队建议还是继续使用。当然,对于 Moment.js 的长期用户,并且已经非常了解它的 API 和局限性,团队表示不必担心进入维护状态这个问题,可以继续使用它。 Moment团队推荐的替代方案包括:Luxon、Day.js、date-fns和js-Joda。他们还说道,希望未来有一天能够完全不需要 JavaScript 的日期和时间库,而是使用语言本身的功能。所以他们还推荐了尚处于实验性阶段的Temporal。

优秀的个人博客,低调大师

谷歌开发类 AirDrop 功能,支持 Windows/Linux/Mac/Chrome OS

外媒消息称, 谷歌已经为 Android 开发了一个类似于 Airdrop 的文件共享服务“Nearly Share”,该功能将允许 Android 用户与其他设备直接共享照片、链接和其他文件,用户可通过Google Play获得。 具体地说,Nearly Share 还可以扩展到 Android 设备之外,可以在 Windows、Linux、macOS 和 Chrome OS 上运行。根据 XDA Developers 的说法,Android最初将此功能命名为“Fast Share”,并已进行了一年多时间的开发。 可以说的是,Nearly Share 将成为 Google Chrome 浏览器功能阵容的一部分,无论平台如何,它都将负责整个共享过程。根据 ChromeStory 的 Dinsan Francis 的最新发现,该功能已经在 Google 浏览器的 Canary 版本中实现,这也意味着其目前已处于相当高级的测试阶段。 值得一提的是,如果将 Nearly Share 安装在 Windows 上,那么该功能则必须与 Microsoft 自己的类似功能“Nearly Sharing”竞争。Nearly Sharing 使 Windows 10 用户可以共享文档、照片、视频、网站链接以及基本上任何可以共享的内容,只要启用了蓝牙和 Wi-Fi,就可以从操作中心访问。 目前,Google 尚未宣布将 Nearest Share 扩展到其他平台,因此暂时来说,这只是该公司尚未准备好确认的测试。不过,鉴于该功能已经在 Google Canary 的公共 Canary 版本中进行了测试,就此而言,其距离官宣可能也不远了。

优秀的个人博客,低调大师

每日一博 | Go testing.common 公共类源码剖析

简介 我们知道单元测试函数需要传递一个testing.T类型的参数,而性能测试函数需要传递一个testing.B类型的参数,该参数可用于控制测试的流程,比如标记测试失败等。 testing.T和testing.B属于testing包中的两个数据类型,该类型提供一系列的方法用于控制函数执行流程,考虑到二者有一定的相似性,所以Go实现时抽象出一个testing.common作为一个基础类型,而testing.T和testing.B则属于testing.common的扩展。 本节,我们重点看testing.common,通过其成员及方法,来了解其实现原理。 数据结构 // common holds the elements common between T and B and // captures common methods such as Errorf. type common struct { mu sync.RWMutex // guards this group of fields output []byte // Output generated by test or benchmark. w io.Writer // For flushToParent. ran bool // Test or benchmark (or one of its subtests) was executed. failed bool // Test or benchmark has failed. skipped bool // Test of benchmark has been skipped. done bool // Test is finished and all subtests have completed. helpers map[string]struct{} // functions to be skipped when writing file/line info chatty bool // A copy of the chatty flag. finished bool // Test function has completed. hasSub int32 // written atomically raceErrors int // number of races detected during test runner string // function name of tRunner running the test parent *common level int // Nesting depth of test or benchmark. creator []uintptr // If level > 0, the stack trace at the point where the parent called t.Run. name string // Name of test or benchmark. start time.Time // Time test or benchmark started duration time.Duration barrier chan bool // To signal parallel subtests they may start. signal chan bool // To signal a test is done. sub []*T // Queue of subtests to be run in parallel. } common.mu 读写锁,仅用于控制本数据内的成员访问。 common.output 存储当前测试产生的日志,每产生一条日志则追加到该切片中,待测试结束后再一并输出。 common.w 子测试执行结束需要把产生的日志输送到父测试中的output切片中,传递时需要考虑缩进等格式调整,通过w把日志传递到父测试。 common.ran 仅表示是否已执行过。比如,跟据某个规范筛选测试,如果没有测试被匹配到的话,则common.ran为false,表示没有测试运行过。 common.failed 如果当前测试执行失败,则置为true。 common.skipped 标记当前测试是否已跳过。 common.done 表示当前测试及其子测试已结束,此状态下再执行Fail()之类的方法标记测试状态会产生panic。 common.helpers 标记当前为函数为help函数,其中打印的日志,在记录日志时不会显示其文件名及行号。 common.chatty 对应命令行中的-v参数,默认为false,true则打印更多详细日志。 common.finished 如果当前测试结束,则置为true。 common.hasSub 标记当前测试是否包含子测试,当测试使用t.Run()方法启动子测试时,t.hasSub则置为1。 common.raceErrors 竞态检测错误数。 common.runner 执行当前测试的函数名。 common.parent 如果当前测试为子测试,则置为父测试的指针。 common.level 测试嵌套层数,比如创建子测试时,子测试嵌套层数就会加1。 common.creator 测试函数调用栈。 common.name 记录每个测试函数名,比如测试函数TestAdd(t *testing.T), 其中t.name即“TestAdd”。 测试结束,打印测试结果会用到该成员。 common.start 记录测试开始的时间。 common.duration 记录测试所花费的时间。 common.barrier 用于控制父测试和子测试执行的channel,如果测试为Parallel,则会阻塞等待父测试结束后再继续。 common.signal 通知当前测试结束。 common.sub 子测试列表。 成员方法 common.Name() // Name returns the name of the running test or benchmark. func (c *common) Name() string { return c.name } 该方法直接返回common结构体中存储的名称。 common.Fail() // Fail marks the function as having failed but continues execution. func (c *common) Fail() { if c.parent != nil { c.parent.Fail() } c.mu.Lock() defer c.mu.Unlock() // c.done needs to be locked to synchronize checks to c.done in parent tests. if c.done { panic("Fail in goroutine after " + c.name + " has completed") } c.failed = true } Fail()方法会标记当前测试为失败,然后继续运行,并不会立即退出当前测试。如果是子测试,则除了标记当前测试结果外还通过c.parent.Fail()来标记父测试失败。 common.FailNow() func (c *common) FailNow() { c.Fail() c.finished = true runtime.Goexit() } FailNow()内部会调用Fail()标记测试失败,还会标记测试结束并退出当前测试协程。 可以简单的把一个测试理解为一个协程,FailNow()只会退出当前协程,并不会影响其他测试协程,但要保证在当前测试协程中调用FailNow()才有效,不可以在当前测试创建的协程中调用该方法。 common.log() func (c *common) log(s string) { c.mu.Lock() defer c.mu.Unlock() c.output = append(c.output, c.decorate(s)...) } common.log()为内部记录日志入口,日志会统一记录到common.output切片中,测试结束时再统一打印出来。 日志记录时会调用common.decorate()进行装饰,即加上文件名和行号,还会做一些其他格式化处理。 调用common.log()的方法,有Log()、Logf()、Error()、Errorf()、Fatal()、Fatalf()、Skip()、Skipf()等。 注意:单元测试中记录的日志只有在执行失败或指定了-v参数才会打印,否则不会打印。而在性能测试中则总是被打印出来,因为是否打印日志有可能影响性能测试结果。 common.Log(args ...interface{}) func (c *common) Log(args ...interface{}) { c.log(fmt.Sprintln(args...)) } common.Log()方法用于记录简单日志,通过fmt.Sprintln()方法生成日志字符串后记录。 common.Logf(format string, args ...interface{}) func (c *common) Logf(format string, args ...interface{}) { c.log(fmt.Sprintf(format, args...)) } common.Logf()方法用于格式化记录日志,通过fmt.Sprintf()生成字符串后记录。 common.Error(args ...interface{}) // Error is equivalent to Log followed by Fail. func (c *common) Error(args ...interface{}) { c.log(fmt.Sprintln(args...)) c.Fail() } common.Error()方法等同于common.Log()+common.Fail(),即记录日志并标记失败,但测试继续进行。 common.Errorf(format string, args ...interface{}) // Errorf is equivalent to Logf followed by Fail. func (c *common) Errorf(format string, args ...interface{}) { c.log(fmt.Sprintf(format, args...)) c.Fail() } common.Errorf()方法等同于common.Logf()+common.Fail(),即记录日志并标记失败,但测试继续进行。 common.Fatal(args ...interface{}) // Fatal is equivalent to Log followed by FailNow. func (c *common) Fatal(args ...interface{}) { c.log(fmt.Sprintln(args...)) c.FailNow() } common.Fatal()方法等同于common.Log()+common.FailNow(),即记录日志、标记失败并退出当前测试。 common.Fatalf(format string, args ...interface{}) // Fatalf is equivalent to Logf followed by FailNow. func (c *common) Fatalf(format string, args ...interface{}) { c.log(fmt.Sprintf(format, args...)) c.FailNow() } common.Fatalf()方法等同于common.Logf()+common.FailNow(),即记录日志、标记失败并退出当前测试。 common.skip() func (c *common) skip() { c.mu.Lock() defer c.mu.Unlock() c.skipped = true } common.skip()方法标记当前测试为已跳过状态,比如测试中检测到某种条件,不再继续测试。该函数仅标记测试跳过,与测试结果无关。测试结果仍然取决于common.failed。 common.SkipNow() func (c *common) SkipNow() { c.skip() c.finished = true runtime.Goexit() } common.SkipNow()方法标记测试跳过,并标记测试结束,最后退出当前测试。 common.Skip(args ...interface{}) // Skip is equivalent to Log followed by SkipNow. func (c *common) Skip(args ...interface{}) { c.log(fmt.Sprintln(args...)) c.SkipNow() } common.Skip()方法等同于common.Log()+common.SkipNow()。 common.Skipf(format string, args ...interface{}) // Skipf is equivalent to Logf followed by SkipNow. func (c *common) Skipf(format string, args ...interface{}) { c.log(fmt.Sprintf(format, args...)) c.SkipNow() } common.Skipf()方法等同于common.Logf() + common.SkipNow()。 common.Helper() // Helper marks the calling function as a test helper function. // When printing file and line information, that function will be skipped. // Helper may be called simultaneously from multiple goroutines. func (c *common) Helper() { c.mu.Lock() defer c.mu.Unlock() if c.helpers == nil { c.helpers = make(map[string]struct{}) } c.helpers[callerName(1)] = struct{}{} } common.Helper()方法标记当前函数为help函数,所谓help函数,即其中打印的日志,不记录help函数的函数名及行号,而是记录上一层函数的函数名和行号。 赠人玫瑰手留余香,如果觉得不错请给个赞~ 本篇文章已归档到GitHub项目,求星~ 点我即达

资源下载

更多资源
Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册