Type test scripts for TypeScript testing

Type test scripts for TypeScript testing
复制标题

用于 TypeScript 测试的类型测试脚本

DOI:
--
复制
发表时间:
2017
期刊:
Proc. ACM Program. Lang.
影响因子:
--
通讯作者:
Anders Møller
Anders Møller
中科院分区:
--
文献类型:
--
作者:
E. Kristensen;Anders Møller

文献摘要

被引文献

相似文献

TypeScript应用通常使用无类型的JavaScript库。为了支持此类应用程序的静态类型检查,库的类型化api被表示为单独的声明文件。这就提出了检查声明文件相对于库实现是否正确的挑战。以前的工作表明,不匹配是经常发生的,并且会导致TypeScript的类型检查器通过拒绝正确的应用程序和接受不正确的应用程序来误导程序员。本文展示了反馈导向的随机测试(一种主要用于测试Java库的自动化测试技术)是如何有效地检测这种类型不匹配的。给定一个带有TypeScript声明文件的JavaScript库,我们的TSTEST工具会生成一个“类型测试脚本”,它是一个与库交互的应用程序,并根据类型声明测试它的行为。与涉及静态分析的替代解决方案相比,这种方法在包含TypeScript声明文件的大量真实JavaScript库中发现了更多的不匹配,并且误报更少。它还有一个优点,即报告的不匹配很容易通过具体执行重现,这有助于诊断和调试。
TypeScript applications often use untyped JavaScript libraries. To support static type checking of such applications, the typed APIs of the libraries are expressed as separate declaration files. This raises the challenge of checking that the declaration files are correct with respect to the library implementations. Previous work has shown that mismatches are frequent and cause TypeScript's type checker to misguide the programmers by rejecting correct applications and accepting incorrect ones. This paper shows how feedback-directed random testing, which is an automated testing technique that has mostly been used for testing Java libraries, can be adapted to effectively detect such type mismatches. Given a JavaScript library with a TypeScript declaration file, our tool TSTEST generates a "type test script", which is an application that interacts with the library and tests that it behaves according to the type declarations. Compared to alternative solutions that involve static analysis, this approach finds significantly more mismatches in a large collection of real-world JavaScript libraries with TypeScript declaration files, and with fewer false positives. It also has the advantage that reported mismatches are easily reproducible with concrete executions, which aids diagnosis and debugging.