summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeert-Jan Zwiers <34610306+GJZwiers@users.noreply.github.com>2021-11-15 15:58:04 +0100
committerGitHub <noreply@github.com>2021-11-15 09:58:04 -0500
commit58e7b290dccbf06abb882daf2ae2b4c1df96f73f (patch)
tree5a404da1b79629758195dd5c3bb103fe30bddaa9
parentdd91ecef502456ba39495d8e178f8101a87c0e34 (diff)
fix(test): support typechecking docs with CRLF line endings (#12748)
-rw-r--r--.dprint.json1
-rw-r--r--.gitattributes3
-rw-r--r--cli/tests/integration/fmt_tests.rs2
-rw-r--r--cli/tests/integration/test_tests.rs6
-rw-r--r--cli/tests/testdata/test/markdown_windows.md31
-rw-r--r--cli/tests/testdata/test/markdown_windows.out7
-rw-r--r--cli/tools/test.rs4
7 files changed, 51 insertions, 3 deletions
diff --git a/.dprint.json b/.dprint.json
index da4351d2c..b9955f135 100644
--- a/.dprint.json
+++ b/.dprint.json
@@ -25,6 +25,7 @@
"cli/tests/testdata/badly_formatted.json",
"cli/tests/testdata/byte_order_mark.ts",
"cli/tests/testdata/fmt/*",
+ "cli/tests/testdata/test/markdown_windows.md",
"cli/tsc/*typescript.js",
"test_util/std",
"test_util/wpt",
diff --git a/.gitattributes b/.gitattributes
index 08ef3b672..1ae3e6d8e 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -12,3 +12,6 @@
# Doesn't include them in the language statistics.
/cli/tsc/00_typescript.js linguist-vendored
/cli/dts/* linguist-vendored
+
+# Keep Windows line endings in cross-platform doc check test file
+/cli/tests/testdata/test/markdown_windows.md eol=crlf
diff --git a/cli/tests/integration/fmt_tests.rs b/cli/tests/integration/fmt_tests.rs
index 1adbc8ff8..304625348 100644
--- a/cli/tests/integration/fmt_tests.rs
+++ b/cli/tests/integration/fmt_tests.rs
@@ -129,7 +129,7 @@ fn fmt_ignore_unexplicit_files() {
}
itest!(fmt_check_tests_dir {
- args: "fmt --check ./ --ignore=.test_coverage,fmt/fmt_with_config/",
+ args: "fmt --check ./ --ignore=.test_coverage,fmt/fmt_with_config/,test/markdown_windows.md",
output: "fmt/expected_fmt_check_tests_dir.out",
exit_code: 1,
});
diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs
index d4412191e..e5d3fd358 100644
--- a/cli/tests/integration/test_tests.rs
+++ b/cli/tests/integration/test_tests.rs
@@ -85,6 +85,12 @@ itest!(markdown {
output: "test/markdown.out",
});
+itest!(markdown_windows {
+ args: "test --doc --allow-all test/markdown_windows.md",
+ exit_code: 1,
+ output: "test/markdown_windows.out",
+});
+
itest!(text {
args: "test --doc --allow-all test/text.md",
exit_code: 0,
diff --git a/cli/tests/testdata/test/markdown_windows.md b/cli/tests/testdata/test/markdown_windows.md
new file mode 100644
index 000000000..d18dbd108
--- /dev/null
+++ b/cli/tests/testdata/test/markdown_windows.md
@@ -0,0 +1,31 @@
+# Documentation
+
+The following block does not have a language attribute and should be ignored:
+
+```
+This is a fenced block without attributes, it's invalid and it should be ignored.
+```
+
+The following block should be given a js extension on extraction:
+
+```js
+console.log("js");
+```
+
+The following block should be given a ts extension on extraction:
+
+```ts
+console.log("ts");
+```
+
+The following example contains the ignore attribute and will be ignored:
+
+```ts ignore
+const value: Invalid = "ignored";
+```
+
+The following example will trigger the type-checker to fail:
+
+```ts
+const a: string = 42;
+```
diff --git a/cli/tests/testdata/test/markdown_windows.out b/cli/tests/testdata/test/markdown_windows.out
new file mode 100644
index 000000000..4810e50cd
--- /dev/null
+++ b/cli/tests/testdata/test/markdown_windows.out
@@ -0,0 +1,7 @@
+Check [WILDCARD]/test/markdown_windows.md$11-14.js
+Check [WILDCARD]/test/markdown_windows.md$17-20.ts
+Check [WILDCARD]/test/markdown_windows.md$29-32.ts
+error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
+const a: string = 42;
+ ^
+ at [WILDCARD]/test/markdown_windows.md$29-32.ts:1:7
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index fba178202..ab2f801da 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -590,7 +590,7 @@ fn extract_files_from_source_comments(
scope_analysis: false,
})?;
let comments = parsed_source.comments().get_vec();
- let blocks_regex = Regex::new(r"```([^\n]*)\n([\S\s]*?)```")?;
+ let blocks_regex = Regex::new(r"```([^\r\n]*)\r?\n([\S\s]*?)```")?;
let lines_regex = Regex::new(r"(?:\* ?)(?:\# ?)?(.*)")?;
let files = comments
@@ -630,7 +630,7 @@ fn extract_files_from_fenced_blocks(
col: 0,
};
- let blocks_regex = Regex::new(r"```([^\n]*)\n([\S\s]*?)```")?;
+ let blocks_regex = Regex::new(r"```([^\r\n]*)\r?\n([\S\s]*?)```")?;
let lines_regex = Regex::new(r"(?:\# ?)?(.*)")?;
extract_files_from_regex_blocks(