Skip to content

Commit 2c2e683

Browse files
authored
test(add): Cover some frontmatter corner cases (#15886)
### What does this PR try to resolve? When working with the frontmatter parser, I identified some corner cases that we should cover. I cannot think of a programmatic way to require escaping when going from no frontmatter to a frontmatter or to require more escaping than is already present. ### How to test and review this PR?
2 parents 0bfd820 + b54b92c commit 2c2e683

File tree

9 files changed

+184
-0
lines changed

9 files changed

+184
-0
lines changed

tests/testsuite/cargo_add/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ mod rustc_incompatible;
147147
mod rustc_latest;
148148
mod rustc_older;
149149
mod script_bare;
150+
mod script_escape;
150151
mod script_frontmatter;
152+
mod script_frontmatter_empty;
151153
mod script_shebang;
152154
mod sorted_table_with_dotted_item;
153155
mod symlink;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---------
2+
[package]
3+
edition = "2015"
4+
description = """
5+
Header
6+
------
7+
8+
Body
9+
"""
10+
---------
11+
12+
fn main() {}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use crate::prelude::*;
2+
use cargo_test_support::Project;
3+
use cargo_test_support::compare::assert_ui;
4+
use cargo_test_support::current_dir;
5+
use cargo_test_support::file;
6+
use cargo_test_support::str;
7+
8+
#[cargo_test]
9+
fn case() {
10+
cargo_test_support::registry::init();
11+
for ver in [
12+
"0.1.1+my-package",
13+
"0.2.0+my-package",
14+
"0.2.3+my-package",
15+
"0.4.1+my-package",
16+
"20.0.0+my-package",
17+
"99999.0.0+my-package",
18+
"99999.0.0-alpha.1+my-package",
19+
] {
20+
cargo_test_support::registry::Package::new("my-package", ver).publish();
21+
}
22+
23+
let project = Project::from_template(current_dir!().join("in"));
24+
let project_root = project.root();
25+
let cwd = &project_root;
26+
27+
snapbox::cmd::Command::cargo_ui()
28+
.masquerade_as_nightly_cargo(&["script"])
29+
.arg("-Zscript")
30+
.arg("add")
31+
.arg_line("--manifest-path cargo-test-fixture.rs my-package")
32+
.current_dir(cwd)
33+
.assert()
34+
.success()
35+
.stdout_eq(str![""])
36+
.stderr_eq(file!["stderr.term.svg"]);
37+
38+
assert_ui().subset_matches(current_dir!().join("out"), &project_root);
39+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---------
2+
[package]
3+
edition = "2015"
4+
description = """
5+
Header
6+
------
7+
8+
Body
9+
"""
10+
11+
[dependencies]
12+
my-package = "99999.0.0"
13+
---------
14+
15+
fn main() {}
Lines changed: 31 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
---
3+
4+
fn main() {}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use crate::prelude::*;
2+
use cargo_test_support::Project;
3+
use cargo_test_support::compare::assert_ui;
4+
use cargo_test_support::current_dir;
5+
use cargo_test_support::file;
6+
use cargo_test_support::str;
7+
8+
#[cargo_test]
9+
fn case() {
10+
cargo_test_support::registry::init();
11+
for ver in [
12+
"0.1.1+my-package",
13+
"0.2.0+my-package",
14+
"0.2.3+my-package",
15+
"0.4.1+my-package",
16+
"20.0.0+my-package",
17+
"99999.0.0+my-package",
18+
"99999.0.0-alpha.1+my-package",
19+
] {
20+
cargo_test_support::registry::Package::new("my-package", ver).publish();
21+
}
22+
23+
let project = Project::from_template(current_dir!().join("in"));
24+
let project_root = project.root();
25+
let cwd = &project_root;
26+
27+
snapbox::cmd::Command::cargo_ui()
28+
.masquerade_as_nightly_cargo(&["script"])
29+
.arg("-Zscript")
30+
.arg("add")
31+
.arg_line("--manifest-path cargo-test-fixture.rs my-package")
32+
.current_dir(cwd)
33+
.assert()
34+
.success()
35+
.stdout_eq(str![""])
36+
.stderr_eq(file!["stderr.term.svg"]);
37+
38+
assert_ui().subset_matches(current_dir!().join("out"), &project_root);
39+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
[dependencies]
3+
my-package = "99999.0.0"
4+
---
5+
6+
fn main() {}
Lines changed: 36 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)