Skip to content

Commit

Permalink
fix(toml): Remove dashed and hashed frontmatter syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
epage authored and bend-n committed May 7, 2024
1 parent 5a6fec5 commit 33d1a63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 86 deletions.
81 changes: 3 additions & 78 deletions src/cargo/util/toml/embedded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,7 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
}

// Experiment: let us try which char works better
let tick_char = source
.content
.chars()
.filter(|c| ['`', '#', '-'].contains(c))
.next()
.unwrap_or('`');
let tick_char = '-';

let tick_end = source
.content
Expand All @@ -235,10 +230,6 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
return Ok(source);
}
1 | 2 => {
if tick_char == '#' {
// Attribute
return Ok(source);
}
anyhow::bail!("found {tick_end} `{tick_char}` in rust frontmatter, expected at least 3")
}
_ => source.content.split_at(tick_end),
Expand Down Expand Up @@ -332,10 +323,10 @@ strip = true
[workspace]
"#,
si!(r#"```cargo
si!(r#"---cargo
[dependencies]
time="0.1.25"
```
---
fn main() {}
"#),
);
Expand Down Expand Up @@ -363,79 +354,13 @@ name = "test-"
[profile.release]
strip = true
[workspace]
"#,
si!(r#"```
[dependencies]
time="0.1.25"
```
fn main() {}
"#),
);
}

#[test]
fn test_dash() {
snapbox::assert_matches(
r#"[[bin]]
name = "test-"
path = [..]
[dependencies]
time = "0.1.25"
[package]
autobenches = false
autobins = false
autoexamples = false
autotests = false
build = false
edition = "2021"
name = "test-"
[profile.release]
strip = true
[workspace]
"#,
si!(r#"---
[dependencies]
time="0.1.25"
---
fn main() {}
"#),
);
}

#[test]
fn test_hash() {
snapbox::assert_matches(
r#"[[bin]]
name = "test-"
path = [..]
[dependencies]
time = "0.1.25"
[package]
autobenches = false
autobins = false
autoexamples = false
autotests = false
build = false
edition = "2021"
name = "test-"
[profile.release]
strip = true
[workspace]
"#,
si!(r#"###
[dependencies]
time="0.1.25"
###
fn main() {}
"#),
);
}
Expand Down
16 changes: 8 additions & 8 deletions tests/testsuite/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ fn requires_z_flag() {
#[cargo_test]
fn clean_output_with_edition() {
let script = r#"#!/usr/bin/env cargo
```cargo
---
[package]
edition = "2018"
```
---
fn main() {
println!("Hello world!");
Expand Down Expand Up @@ -241,9 +241,9 @@ fn main() {
#[cargo_test]
fn warning_without_edition() {
let script = r#"#!/usr/bin/env cargo
```cargo
---
[package]
```
---
fn main() {
println!("Hello world!");
Expand Down Expand Up @@ -714,10 +714,10 @@ fn did_you_mean_command_stable() {
fn test_name_same_as_dependency() {
Package::new("script", "1.0.0").publish();
let script = r#"#!/usr/bin/env cargo
```cargo
---
[dependencies]
script = "1.0.0"
```
---
fn main() {
println!("Hello world!");
Expand Down Expand Up @@ -751,10 +751,10 @@ fn main() {
#[cargo_test]
fn test_path_dep() {
let script = r#"#!/usr/bin/env cargo
```cargo
---
[dependencies]
bar.path = "./bar"
```
---
fn main() {
println!("Hello world!");
Expand Down

0 comments on commit 33d1a63

Please sign in to comment.