From 5f95796b6186f9c7a183907ee84601f5ff7f5edc Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 25 Apr 2019 10:37:41 +0200 Subject: [PATCH] test: fix ts api guardian and public guard tests on windows (#30105) This change addresses several issues with ts-api-guardian and public api guards related tests in Windows The fixes contain 3 main changes: 1) In `stripExportPattern` - replace `^` with `^^^^` in RegExp due to a double escaping requirment under Windows. Note that under Linux this the extra character has no effect because it's still a valid RegExp in Js. 2. Force `*.patch` files to always be with a LF line sequence instead of CRLF in windows 3. When adding JSDoc comments consider the presence of a carriage return in a line new feed Partially addresses #29785 PR Close #30105 --- .gitattributes | 3 +++ tools/ts-api-guardian/index.bzl | 3 ++- tools/ts-api-guardian/lib/serializer.ts | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitattributes b/.gitattributes index 0acf0cd70d..b45635737c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,5 +5,8 @@ *.js eol=lf *.ts eol=lf +# API guardian patch must always use LF for tests to work +*.patch eol=lf + # Must keep Windows line ending to be parsed correctly scripts/windows/packages.txt eol=crlf diff --git a/tools/ts-api-guardian/index.bzl b/tools/ts-api-guardian/index.bzl index aac9136a58..a33863f7f3 100644 --- a/tools/ts-api-guardian/index.bzl +++ b/tools/ts-api-guardian/index.bzl @@ -51,7 +51,8 @@ def ts_api_guardian_test( ] for i in strip_export_pattern: - args += ["--stripExportPattern", i] + # The below replacement is needed because under Windows '^' needs to be escaped twice + args += ["--stripExportPattern", i.replace("^", "^^^^")] for i in allow_module_identifiers: args += ["--allowModuleIdentifiers", i] diff --git a/tools/ts-api-guardian/lib/serializer.ts b/tools/ts-api-guardian/lib/serializer.ts index 1f4402ad48..d04bc3b2d8 100644 --- a/tools/ts-api-guardian/lib/serializer.ts +++ b/tools/ts-api-guardian/lib/serializer.ts @@ -298,7 +298,7 @@ class ResolvedDeclarationEmitter { const jsdocComment = this.processJsDocTags(node, tagOptions); if (jsdocComment) { // Add the annotation after the leading whitespace - output = output.replace(/^(\n\s*)/, `$1${jsdocComment} `); + output = output.replace(/^(\r?\n\s*)/, `$1${jsdocComment} `); } }