-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fill explicit
lib
declaration with default values (#38)
* Move `autolib` test to a dedicated file * tests/autolib: Remove unnecessary manifest entries We only care about the library auto-discovery here, the rest is just noise. * Fill explicit `lib` declaration with default values Previously, it was only possible to either use the auto-discovered lib target or explicitly declare one. In reality, cargo merges the definitions though. It is for example possible to rely on the auto-discovered `src/lib.rs`, but rename the library via `lib.name`. This commit changes the `lib = Some(_)` code path to assign proper defaults to the `name`, `path`, `edition`, and `crate_type` fields unless they are explicitly specified, which matches the behavior from cargo.
- Loading branch information
Showing
22 changed files
with
233 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use cargo_manifest::Manifest; | ||
|
||
#[test] | ||
fn test_bin() { | ||
let m = Manifest::from_path("tests/autolib/bin/Cargo.toml").unwrap(); | ||
assert!(m.lib.is_none()); | ||
} | ||
|
||
#[test] | ||
fn test_lib_rs() { | ||
let m = Manifest::from_path("tests/autolib/lib_rs/Cargo.toml").unwrap(); | ||
|
||
let lib = m.lib.unwrap(); | ||
assert_eq!(lib.path.as_deref(), Some("src/lib.rs")); | ||
assert_eq!(lib.name.as_deref(), Some("auto_lib")); | ||
|
||
insta::assert_debug_snapshot!(lib); | ||
} | ||
|
||
#[test] | ||
fn test_name_override() { | ||
let m = Manifest::from_path("tests/autolib/name_override/Cargo.toml").unwrap(); | ||
|
||
let lib = m.lib.unwrap(); | ||
assert_eq!(lib.path.as_deref(), Some("src/lib.rs")); | ||
assert_eq!(lib.name.as_deref(), Some("foo")); | ||
|
||
insta::assert_debug_snapshot!(lib); | ||
} | ||
|
||
#[test] | ||
fn test_path_override() { | ||
let m = Manifest::from_path("tests/autolib/path_override/Cargo.toml").unwrap(); | ||
|
||
let lib = m.lib.unwrap(); | ||
assert_eq!(lib.path.as_deref(), Some("src/foo.rs")); | ||
assert_eq!(lib.name.as_deref(), Some("auto_lib")); | ||
|
||
insta::assert_debug_snapshot!(lib); | ||
} | ||
|
||
#[test] | ||
fn test_other_override() { | ||
let m = Manifest::from_path("tests/autolib/other_override/Cargo.toml").unwrap(); | ||
|
||
let lib = m.lib.unwrap(); | ||
assert!(!lib.test); | ||
assert!(lib.proc_macro); | ||
|
||
insta::assert_debug_snapshot!(lib); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[package] | ||
name = "auto-lib" | ||
version = "0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[package] | ||
name = "auto-lib" | ||
version = "0.1.0" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "auto-lib" | ||
version = "0.1.0" | ||
|
||
[lib] | ||
name = "foo" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "auto-lib" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[lib] | ||
proc-macro = true | ||
test = false |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "auto-lib" | ||
version = "0.1.0" | ||
|
||
[lib] | ||
path = "src/foo.rs" |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
source: tests/autolib.rs | ||
expression: lib | ||
--- | ||
Product { | ||
path: Some( | ||
"src/lib.rs", | ||
), | ||
name: Some( | ||
"auto_lib", | ||
), | ||
test: true, | ||
doctest: true, | ||
bench: true, | ||
doc: true, | ||
plugin: false, | ||
proc_macro: false, | ||
harness: true, | ||
edition: None, | ||
required_features: [], | ||
crate_type: Some( | ||
[ | ||
"lib", | ||
], | ||
), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
source: tests/autolib.rs | ||
expression: lib | ||
--- | ||
Product { | ||
path: Some( | ||
"src/lib.rs", | ||
), | ||
name: Some( | ||
"foo", | ||
), | ||
test: true, | ||
doctest: true, | ||
bench: true, | ||
doc: true, | ||
plugin: false, | ||
proc_macro: false, | ||
harness: true, | ||
edition: None, | ||
required_features: [], | ||
crate_type: Some( | ||
[ | ||
"lib", | ||
], | ||
), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
source: tests/autolib.rs | ||
expression: lib | ||
--- | ||
Product { | ||
path: Some( | ||
"src/lib.rs", | ||
), | ||
name: Some( | ||
"auto_lib", | ||
), | ||
test: false, | ||
doctest: true, | ||
bench: true, | ||
doc: true, | ||
plugin: false, | ||
proc_macro: true, | ||
harness: true, | ||
edition: Some( | ||
E2018, | ||
), | ||
required_features: [], | ||
crate_type: Some( | ||
[ | ||
"lib", | ||
], | ||
), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
source: tests/autolib.rs | ||
expression: lib | ||
--- | ||
Product { | ||
path: Some( | ||
"src/foo.rs", | ||
), | ||
name: Some( | ||
"auto_lib", | ||
), | ||
test: true, | ||
doctest: true, | ||
bench: true, | ||
doc: true, | ||
plugin: false, | ||
proc_macro: false, | ||
harness: true, | ||
edition: None, | ||
required_features: [], | ||
crate_type: Some( | ||
[ | ||
"lib", | ||
], | ||
), | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.