diff --git a/src/main.rs b/src/main.rs index 3be0a71e..f069853f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,36 +38,25 @@ use dot_printer::DotPrinter; fn choose_target<'a>(args: &Arguments, manifest: &'a Manifest) -> Result<&'a Target, Error> { if args.lib { // If `--lib` is enabled use the first library target. - manifest - .targets - .iter() - .find(|t| t.is_lib()) - .ok_or(Error::NoLibraryTargetFound) + manifest.lib() } else if let Some(ref name) = args.bin { // If a binary target is specified use that. - manifest - .targets - .iter() - .find(|t| t.is_bin() && t.name() == name) - .ok_or(Error::NoMatchingBinaryTargetFound) - } else if manifest.targets.len() == 1 { + manifest.bin(name) + } else if manifest.targets().len() == 1 { // If neither `--lib` is enabled nor `--bin` target is specified but // there is only one target, use that. - Ok(manifest.targets.first().unwrap()) + Ok(manifest.targets().first().unwrap()) } else { // If there are multiple targets use the first library target. - manifest - .targets - .iter() - .find(|t| t.is_lib()) - .ok_or(Error::NoTargetProvided) + manifest.lib().or(Err(Error::NoTargetProvided)) } } fn run(args: &Arguments) -> Result<(), Error> { let manifest: Manifest = { let output = process::Command::new("cargo") - .arg("read-manifest") + .arg("metadata") + .args(&["--no-deps", "--format-version", "1"]) .output() .map_err(Error::CargoExecutionFailed)?; let stdout = output.stdout; @@ -78,14 +67,6 @@ fn run(args: &Arguments) -> Result<(), Error> { Manifest::from_str(&json_string)? }; - if args.enable_edition_2018 && manifest.edition == Edition::E2018 { - println!( - "{}\n{}", - "Edition 2018 support is work in progress.".red(), - "`--enable-edition-2018` will be ignored.".red() - ); - } - // TODO: Check to see if build scripts really need to be ignored. // Seems like they are not mistaken as orphans anyway. let build_scripts: Vec = manifest @@ -95,6 +76,15 @@ fn run(args: &Arguments) -> Result<(), Error> { .collect(); let target: &Target = choose_target(args, &manifest)?; + + if args.enable_edition_2018 && target.edition == Edition::E2018 { + println!( + "{}\n{}", + "Edition 2018 support is work in progress.".red(), + "`--enable-edition-2018` will be ignored.".red() + ); + } + let parse_session = ParseSess::new(source_map::FilePathMapping::empty()); syntax::with_globals(|| { diff --git a/src/manifest.rs b/src/manifest.rs index 438b83ed..f3f64923 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -3,34 +3,71 @@ use json; use std::default::Default; use std::path::{Path, PathBuf}; +#[derive(Debug, Default)] +pub struct Package { + edition: Edition, + targets: Vec, +} + #[derive(Debug, Default)] pub struct Manifest { - pub edition: Edition, - pub targets: Vec, + packages: Vec, } impl Manifest { pub fn from_str(src: &str) -> Result { let mut j = json::parse(src).map_err(Error::InvalidManifestJson)?; - let edition: Edition = match j["edition"].as_str() { - Some("2015") => Edition::E2015, - Some("2018") => Edition::E2018, - Some(unknown) => panic!("Unrecognized value for edition \"{}\"", unknown), - None => Edition::default(), - }; + let packages = j["packages"] + .members_mut() + .map(|package| { + let edition: Edition = match package["edition"].as_str() { + Some("2015") => Edition::E2015, + Some("2018") => Edition::E2018, + Some(unknown) => panic!("Unrecognized value for edition \"{}\"", unknown), + None => Edition::default(), + }; + + let targets: Vec = package["targets"] + .members_mut() + .map(Target::from_json) + .collect(); - let targets: Vec = j["targets"].members_mut().map(Target::from_json).collect(); + Package { edition, targets } + }) + .collect(); - Result::Ok(Manifest { edition, targets }) + Result::Ok(Manifest { packages }) } - pub fn custom_builds(&self) -> Vec<&Target> { - self.targets + fn all_targets(&self) -> impl Iterator { + self.packages .iter() - .filter(|t| t.is_custom_build()) + .flat_map(|package| package.targets.iter()) + } + + pub fn custom_builds(&self) -> Vec<&Target> { + self.all_targets().filter(|t| t.is_custom_build()).collect() + } + + /// All valid targets that can be used to display modules + pub fn targets(&self) -> Vec<&Target> { + self.all_targets() + .filter(|t| t.is_bin() || t.is_lib() || t.is_proc_macro()) .collect() } + + pub fn lib(&self) -> Result<&Target, Error> { + self.all_targets() + .find(|t| t.is_lib()) + .ok_or(Error::NoLibraryTargetFound) + } + + pub fn bin(&self, name: &str) -> Result<&Target, Error> { + self.all_targets() + .find(|t| t.is_bin() && t.name() == name) + .ok_or(Error::NoMatchingBinaryTargetFound) + } } #[derive(Clone, Copy, Debug, PartialEq)] @@ -51,7 +88,7 @@ pub struct Target { crate_types: Vec, name: String, src_path: PathBuf, - edition: Option, + pub edition: Edition, } impl Target { @@ -73,6 +110,10 @@ impl Target { self.kind.iter().any(|k| Self::LIB_KINDS.contains(&&k[..])) } + pub fn is_proc_macro(&self) -> bool { + self.kind.contains(&String::from("proc-macro")) + } + fn from_json(j: &mut json::JsonValue) -> Target { let kind: Vec = { assert!(j["kind"].is_array()); @@ -91,7 +132,12 @@ impl Target { let name: String = j["name"].take_string().expect("name is missing"); let src_path: PathBuf = Path::new(&j["src_path"].take_string().expect("src_path is missing")).to_path_buf(); - let edition: Option = j["edition"].take_string(); + let edition: Edition = match j["edition"].as_str() { + Some("2015") => Edition::E2015, + Some("2018") => Edition::E2018, + Some(unknown) => panic!("Unrecognized value for edition \"{}\"", unknown), + None => Edition::default(), + }; Target { kind, crate_types, @@ -109,94 +155,200 @@ impl Target { #[cfg(test)] mod tests { use super::*; - use std::fs; + use std::path; + use std::process; - fn read_manifest(filename: &str) -> Manifest { - let manifest_str: String = - fs::read_to_string(filename).expect("manifest file cannot be read"); + fn read_manifest(directory: &path::Path) -> Manifest { + let output = process::Command::new("cargo") + .current_dir(directory) + .arg("metadata") + .args(&["--no-deps", "--format-version", "1"]) + .output() + .expect("Cargo failed") + .stdout; + let manifest_str = String::from_utf8(output).expect("Failed reading cargo output"); Manifest::from_str(&manifest_str).expect("manifest cannot be read") } #[test] fn manifest_with_edition2018_can_be_parsed() { - let manifest = read_manifest("test-resources/example-edition-2018.json"); - assert_eq!(Edition::E2018, manifest.edition); + let manifest = read_manifest(path::Path::new("test-resources/example-lib-edition-2018")); + assert_eq!(Edition::E2018, manifest.targets()[0].edition); } #[test] fn manifest_with_edition2015_can_be_parsed() { - let manifest = read_manifest("test-resources/example-edition-2015.json"); - assert_eq!(Edition::E2015, manifest.edition); + let manifest = read_manifest(path::Path::new("test-resources/example-lib-edition-2015")); + assert_eq!(Edition::E2015, manifest.targets()[0].edition); } #[test] fn manifest_without_edition_can_be_parsed() { - let manifest = read_manifest("test-resources/example-no-edition.json"); - assert_eq!(Edition::E2015, manifest.edition); + let manifest = read_manifest(path::Path::new("test-resources/example-lib-no-edition")); + assert_eq!(Edition::E2015, manifest.targets()[0].edition); } #[test] fn manifest_for_simple_lib() { - let manifest = read_manifest("test-resources/example-lib.json"); + let resource_path = path::Path::new("test-resources/example-lib-edition-2018"); + let manifest = read_manifest(resource_path); assert_eq!( - Target { + &Target { kind: vec!(String::from("lib")), crate_types: vec!(String::from("lib")), - name: String::from("example-lib"), - src_path: Path::new("/home/muhuk/Documents/code/example-lib/src/lib.rs") - .to_path_buf(), - edition: Some(String::from("2018")) + name: String::from("example-lib-edition-2018"), + src_path: resource_path.join("src/lib.rs").canonicalize().unwrap(), + edition: Edition::E2018 }, - manifest.targets[0] + manifest.targets()[0] ); - assert!(manifest.targets[0].is_lib()); - assert!(!manifest.targets[0].is_bin()); + assert!(manifest.targets()[0].is_lib()); + assert!(!manifest.targets()[0].is_bin()); } #[test] fn manifest_for_simple_bin() { - let manifest = read_manifest("test-resources/example-bin.json"); + let resource_path = path::Path::new("test-resources/example-bin"); + let manifest = read_manifest(resource_path); assert_eq!( - Target { - kind: vec!(String::from("bin")), - crate_types: vec!(String::from("bin")), - name: String::from("example-bin"), - src_path: Path::new("/home/muhuk/Documents/code/example-bin/src/main.rs") - .to_path_buf(), - edition: Some(String::from("2018")) - }, - manifest.targets[0] + vec![ + &Target { + kind: vec!(String::from("bin")), + crate_types: vec!(String::from("bin")), + name: String::from("example2"), + src_path: resource_path + .join("src/bin/example2.rs") + .canonicalize() + .unwrap(), + edition: Edition::E2018 + }, + &Target { + kind: vec!(String::from("bin")), + crate_types: vec!(String::from("bin")), + name: String::from("example"), + src_path: resource_path + .join("src/bin/example.rs") + .canonicalize() + .unwrap(), + edition: Edition::E2018 + } + ], + manifest.targets() ); - assert!(manifest.targets[0].is_bin()); - assert!(!manifest.targets[0].is_lib()); + assert!(manifest.targets()[0].is_bin()); + assert!(!manifest.targets()[0].is_lib()); } #[test] fn manifest_with_custom_build() { - let manifest = read_manifest("test-resources/example-custom-build.json"); + let resource_path = path::Path::new("test-resources/example-lib-edition-2018"); + let manifest = read_manifest(resource_path); assert_eq!( vec![ - Target { + &Target { kind: vec!(String::from("lib")), crate_types: vec!(String::from("lib")), - name: String::from("example-custom-build"), - src_path: Path::new( - "/home/muhuk/Documents/code/example-custom-build/src/lib.rs" - ) - .to_path_buf(), - edition: Some(String::from("2018")) + name: String::from("example-lib-edition-2018"), + src_path: resource_path.join("src/lib.rs").canonicalize().unwrap(), + edition: Edition::E2018 }, - Target { + &Target { kind: vec!(String::from("custom-build")), crate_types: vec!(String::from("bin")), name: String::from("build-script-build"), - src_path: Path::new("/home/muhuk/Documents/code/example-custom-build/build.rs") - .to_path_buf(), - edition: Some(String::from("2018")) + src_path: resource_path.join("build.rs").canonicalize().unwrap(), + edition: Edition::E2018 + } + ], + manifest.all_targets().collect::>() + ); + assert_eq!( + vec![&Target { + kind: vec!(String::from("lib")), + crate_types: vec!(String::from("lib")), + name: String::from("example-lib-edition-2018"), + src_path: resource_path.join("src/lib.rs").canonicalize().unwrap(), + edition: Edition::E2018 + },], + manifest.targets() + ); + assert_eq!( + vec![&Target { + kind: vec!(String::from("custom-build")), + crate_types: vec!(String::from("bin")), + name: String::from("build-script-build"), + src_path: resource_path.join("build.rs").canonicalize().unwrap(), + edition: Edition::E2018 + }], + manifest.custom_builds() + ); + } + + #[test] + fn manifest_for_plugin() { + let resource_path = path::Path::new("test-resources/example-plugin"); + let manifest = read_manifest(resource_path); + assert_eq!( + &Target { + kind: vec!(String::from("dylib")), + crate_types: vec!(String::from("dylib")), + name: String::from("example-plugin"), + src_path: resource_path.join("src/lib.rs").canonicalize().unwrap(), + edition: Edition::E2018 + }, + manifest.targets()[0] + ); + assert!(manifest.targets()[0].is_lib()); + assert!(!manifest.targets()[0].is_bin()); + } + + #[test] + fn manifest_for_proc_macro() { + let resource_path = path::Path::new("test-resources/example-proc-macro"); + let manifest = read_manifest(resource_path); + assert_eq!( + &Target { + kind: vec!(String::from("proc-macro")), + crate_types: vec!(String::from("proc-macro")), + name: String::from("example-proc-macro"), + src_path: resource_path.join("src/lib.rs").canonicalize().unwrap(), + edition: Edition::E2018 + }, + manifest.targets()[0] + ); + assert!(!manifest.targets()[0].is_lib()); + assert!(!manifest.targets()[0].is_bin()); + assert!(manifest.targets()[0].is_proc_macro()); + } + + #[test] + fn manifest_for_bin_and_lib() { + let resource_path = path::Path::new("test-resources/example-bin-and-lib"); + let manifest = read_manifest(resource_path); + assert_eq!( + vec![ + &Target { + kind: vec!(String::from("lib")), + crate_types: vec!(String::from("lib")), + name: String::from("example-bin-and-lib"), + src_path: resource_path.join("src/lib.rs").canonicalize().unwrap(), + edition: Edition::E2018 + }, + &Target { + kind: vec!(String::from("bin")), + crate_types: vec!(String::from("bin")), + name: String::from("example-bin-and-lib"), + src_path: resource_path.join("src/main.rs").canonicalize().unwrap(), + edition: Edition::E2018 } ], - manifest.targets + manifest.targets() ); - assert!(manifest.targets[1].is_custom_build()); + assert!(manifest.targets()[0].is_lib()); + assert!(!manifest.targets()[0].is_bin()); + assert!(!manifest.targets()[0].is_proc_macro()); + assert!(!manifest.targets()[1].is_lib()); + assert!(manifest.targets()[1].is_bin()); + assert!(!manifest.targets()[1].is_proc_macro()); } } diff --git a/test-resources/example-bin-and-lib/Cargo.lock b/test-resources/example-bin-and-lib/Cargo.lock new file mode 100644 index 00000000..360cd13f --- /dev/null +++ b/test-resources/example-bin-and-lib/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "example-bin" +version = "0.1.0" + diff --git a/test-resources/example-bin-and-lib/Cargo.toml b/test-resources/example-bin-and-lib/Cargo.toml new file mode 100644 index 00000000..99e83566 --- /dev/null +++ b/test-resources/example-bin-and-lib/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "example-bin-and-lib" +version = "0.1.0" +authors = ["Name "] +edition = "2018" + +[dependencies] diff --git a/test-resources/example-bin-and-lib/build.rs b/test-resources/example-bin-and-lib/build.rs new file mode 100644 index 00000000..4f00efe6 --- /dev/null +++ b/test-resources/example-bin-and-lib/build.rs @@ -0,0 +1,6 @@ +//xx + + +fn main() { + +} \ No newline at end of file diff --git a/test-resources/example-bin-and-lib/examples/example.rs b/test-resources/example-bin-and-lib/examples/example.rs new file mode 100644 index 00000000..f328e4d9 --- /dev/null +++ b/test-resources/example-bin-and-lib/examples/example.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/test-resources/example-bin-and-lib/src/lib.rs b/test-resources/example-bin-and-lib/src/lib.rs new file mode 100644 index 00000000..31e1bb20 --- /dev/null +++ b/test-resources/example-bin-and-lib/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/test-resources/example-bin-and-lib/src/main.rs b/test-resources/example-bin-and-lib/src/main.rs new file mode 100644 index 00000000..e7a11a96 --- /dev/null +++ b/test-resources/example-bin-and-lib/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/test-resources/example-bin-and-lib/tests/test.rs b/test-resources/example-bin-and-lib/tests/test.rs new file mode 100644 index 00000000..f328e4d9 --- /dev/null +++ b/test-resources/example-bin-and-lib/tests/test.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/test-resources/example-bin.json b/test-resources/example-bin.json deleted file mode 100644 index d2eadc33..00000000 --- a/test-resources/example-bin.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "example-bin", - "version": "0.1.0", - "id": "example-bin 0.1.0 (path+file:///home/muhuk/Documents/code/example-bin)", - "license": null, - "license_file": null, - "description": null, - "source": null, - "dependencies": [], - "targets": [ - { - "kind": [ - "bin" - ], - "crate_types": [ - "bin" - ], - "name": "example-bin", - "src_path": "/home/muhuk/Documents/code/example-bin/src/main.rs", - "edition": "2018" - } - ], - "features": null, - "manifest_path": "/home/muhuk/Documents/code/example-bin/Cargo.toml", - "metadata": null, - "authors": [ - "Atamert Ölçgen " - ], - "categories": [], - "keywords": [], - "readme": null, - "repository": null, - "edition": "2018", - "links": null -} diff --git a/test-resources/example-bin/Cargo.toml b/test-resources/example-bin/Cargo.toml new file mode 100644 index 00000000..f5363a91 --- /dev/null +++ b/test-resources/example-bin/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "example-bin" +version = "0.1.0" +authors = ["Name "] +edition = "2018" + +[dependencies] diff --git a/test-resources/example-bin/build.rs b/test-resources/example-bin/build.rs new file mode 100644 index 00000000..4f00efe6 --- /dev/null +++ b/test-resources/example-bin/build.rs @@ -0,0 +1,6 @@ +//xx + + +fn main() { + +} \ No newline at end of file diff --git a/test-resources/example-bin/src/bin/example.rs b/test-resources/example-bin/src/bin/example.rs new file mode 100644 index 00000000..e7a11a96 --- /dev/null +++ b/test-resources/example-bin/src/bin/example.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/test-resources/example-bin/src/bin/example2.rs b/test-resources/example-bin/src/bin/example2.rs new file mode 100644 index 00000000..e7a11a96 --- /dev/null +++ b/test-resources/example-bin/src/bin/example2.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/test-resources/example-custom-build.json b/test-resources/example-custom-build.json deleted file mode 100644 index b767604a..00000000 --- a/test-resources/example-custom-build.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "example-custom-build", - "version": "0.1.0", - "id": "example-custom-build 0.1.0 (path+file:///home/muhuk/Documents/code/example-custom-build)", - "license": null, - "license_file": null, - "description": null, - "source": null, - "dependencies": [], - "targets": [ - { - "kind": [ - "lib" - ], - "crate_types": [ - "lib" - ], - "name": "example-custom-build", - "src_path": "/home/muhuk/Documents/code/example-custom-build/src/lib.rs", - "edition": "2018" - }, - { - "kind": [ - "custom-build" - ], - "crate_types": [ - "bin" - ], - "name": "build-script-build", - "src_path": "/home/muhuk/Documents/code/example-custom-build/build.rs", - "edition": "2018" - } - ], - "features": null, - "manifest_path": "/home/muhuk/Documents/code/example-custom-build/Cargo.toml", - "metadata": null, - "authors": [ - "Atamert Ölçgen " - ], - "categories": [], - "keywords": [], - "readme": null, - "repository": null, - "edition": "2018", - "links": null -} diff --git a/test-resources/example-edition-2015.json b/test-resources/example-edition-2015.json deleted file mode 100644 index 0f0148c1..00000000 --- a/test-resources/example-edition-2015.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "example-edition-2015", - "version": "0.1.0", - "id": "example-edition-2015 0.1.0 (path+file:///home/muhuk/Documents/code/example-edition-2015)", - "license": null, - "license_file": null, - "description": null, - "source": null, - "dependencies": [], - "targets": [ - { - "kind": [ - "lib" - ], - "crate_types": [ - "lib" - ], - "name": "example-edition-2015", - "src_path": "/home/muhuk/Documents/code/example-edition-2015/src/lib.rs", - "edition": "2015" - } - ], - "features": null, - "manifest_path": "/home/muhuk/Documents/code/example-edition-2015/Cargo.toml", - "metadata": null, - "authors": [ - "Atamert Ölçgen " - ], - "categories": [], - "keywords": [], - "readme": null, - "repository": null, - "edition": "2015", - "links": null -} diff --git a/test-resources/example-edition-2018.json b/test-resources/example-edition-2018.json deleted file mode 100644 index eccaa458..00000000 --- a/test-resources/example-edition-2018.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "example-edition-2018", - "version": "0.1.0", - "id": "example-edition-2018 0.1.0 (path+file:///home/muhuk/Documents/code/example-edition-2018)", - "license": null, - "license_file": null, - "description": null, - "source": null, - "dependencies": [], - "targets": [ - { - "kind": [ - "lib" - ], - "crate_types": [ - "lib" - ], - "name": "example-edition-2018", - "src_path": "/home/muhuk/Documents/code/example-edition-2018/src/lib.rs", - "edition": "2018" - } - ], - "features": null, - "manifest_path": "/home/muhuk/Documents/code/example-edition-2018/Cargo.toml", - "metadata": null, - "authors": [ - "Atamert Ölçgen " - ], - "categories": [], - "keywords": [], - "readme": null, - "repository": null, - "edition": "2018", - "links": null -} diff --git a/test-resources/example-lib-edition-2015/Cargo.toml b/test-resources/example-lib-edition-2015/Cargo.toml new file mode 100644 index 00000000..1cf0ae4a --- /dev/null +++ b/test-resources/example-lib-edition-2015/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "example-lib-edition-2015" +version = "0.1.0" +authors = ["Name "] +edition = "2015" + +[dependencies] diff --git a/test-resources/example-lib-edition-2015/build.rs b/test-resources/example-lib-edition-2015/build.rs new file mode 100644 index 00000000..4f00efe6 --- /dev/null +++ b/test-resources/example-lib-edition-2015/build.rs @@ -0,0 +1,6 @@ +//xx + + +fn main() { + +} \ No newline at end of file diff --git a/test-resources/example-lib-edition-2015/src/lib.rs b/test-resources/example-lib-edition-2015/src/lib.rs new file mode 100644 index 00000000..31e1bb20 --- /dev/null +++ b/test-resources/example-lib-edition-2015/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/test-resources/example-lib-edition-2018/Cargo.toml b/test-resources/example-lib-edition-2018/Cargo.toml new file mode 100644 index 00000000..0e26e3e0 --- /dev/null +++ b/test-resources/example-lib-edition-2018/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "example-lib-edition-2018" +version = "0.1.0" +authors = ["Name "] +edition = "2018" + +[dependencies] diff --git a/test-resources/example-lib-edition-2018/build.rs b/test-resources/example-lib-edition-2018/build.rs new file mode 100644 index 00000000..4f00efe6 --- /dev/null +++ b/test-resources/example-lib-edition-2018/build.rs @@ -0,0 +1,6 @@ +//xx + + +fn main() { + +} \ No newline at end of file diff --git a/test-resources/example-lib-edition-2018/src/lib.rs b/test-resources/example-lib-edition-2018/src/lib.rs new file mode 100644 index 00000000..31e1bb20 --- /dev/null +++ b/test-resources/example-lib-edition-2018/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/test-resources/example-lib-no-edition/Cargo.toml b/test-resources/example-lib-no-edition/Cargo.toml new file mode 100644 index 00000000..9689ff27 --- /dev/null +++ b/test-resources/example-lib-no-edition/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "example-lib" +version = "0.1.0" +authors = ["Name "] + +[dependencies] diff --git a/test-resources/example-lib-no-edition/src/lib.rs b/test-resources/example-lib-no-edition/src/lib.rs new file mode 100644 index 00000000..31e1bb20 --- /dev/null +++ b/test-resources/example-lib-no-edition/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/test-resources/example-lib.json b/test-resources/example-lib.json deleted file mode 100644 index fa0be66d..00000000 --- a/test-resources/example-lib.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "example-lib", - "version": "0.1.0", - "id": "example-lib 0.1.0 (path+file:///home/muhuk/Documents/code/example-lib)", - "license": null, - "license_file": null, - "description": null, - "source": null, - "dependencies": [], - "targets": [ - { - "kind": [ - "lib" - ], - "crate_types": [ - "lib" - ], - "name": "example-lib", - "src_path": "/home/muhuk/Documents/code/example-lib/src/lib.rs", - "edition": "2018" - } - ], - "features": null, - "manifest_path": "/home/muhuk/Documents/code/example-lib/Cargo.toml", - "metadata": null, - "authors": [ - "Atamert Ölçgen " - ], - "categories": [], - "keywords": [], - "readme": null, - "repository": null, - "edition": "2018", - "links": null -} diff --git a/test-resources/example-no-edition.json b/test-resources/example-no-edition.json deleted file mode 100644 index 6204a011..00000000 --- a/test-resources/example-no-edition.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "example-no-edition", - "version": "0.1.0", - "id": "example-no-edition 0.1.0 (path+file:///home/muhuk/Documents/code/example-no-edition)", - "license": null, - "license_file": null, - "description": null, - "source": null, - "dependencies": [], - "targets": [ - { - "kind": [ - "lib" - ], - "crate_types": [ - "lib" - ], - "name": "example-no-edition", - "src_path": "/home/muhuk/Documents/code/example-no-edition/src/lib.rs", - "edition": "2018" - } - ], - "features": null, - "manifest_path": "/home/muhuk/Documents/code/example-no-edition/Cargo.toml", - "metadata": null, - "authors": [ - "Atamert Ölçgen " - ], - "categories": [], - "keywords": [], - "readme": null, - "repository": null, - "links": null -} diff --git a/test-resources/example-plugin/Cargo.toml b/test-resources/example-plugin/Cargo.toml new file mode 100644 index 00000000..7cf2f4cc --- /dev/null +++ b/test-resources/example-plugin/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "example-plugin" +version = "0.1.0" +authors = ["Name "] +edition = "2018" + +[lib] +plugin = true + +[dependencies] diff --git a/test-resources/example-plugin/build.rs b/test-resources/example-plugin/build.rs new file mode 100644 index 00000000..4f00efe6 --- /dev/null +++ b/test-resources/example-plugin/build.rs @@ -0,0 +1,6 @@ +//xx + + +fn main() { + +} \ No newline at end of file diff --git a/test-resources/example-plugin/src/lib.rs b/test-resources/example-plugin/src/lib.rs new file mode 100644 index 00000000..31e1bb20 --- /dev/null +++ b/test-resources/example-plugin/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/test-resources/example-proc-macro/Cargo.toml b/test-resources/example-proc-macro/Cargo.toml new file mode 100644 index 00000000..a7b95c3f --- /dev/null +++ b/test-resources/example-proc-macro/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "example-proc-macro" +version = "0.1.0" +authors = ["Name "] +edition = "2018" + +[lib] +proc-macro = true + +[dependencies] diff --git a/test-resources/example-proc-macro/build.rs b/test-resources/example-proc-macro/build.rs new file mode 100644 index 00000000..4f00efe6 --- /dev/null +++ b/test-resources/example-proc-macro/build.rs @@ -0,0 +1,6 @@ +//xx + + +fn main() { + +} \ No newline at end of file diff --git a/test-resources/example-proc-macro/src/lib.rs b/test-resources/example-proc-macro/src/lib.rs new file mode 100644 index 00000000..e7fa1ec7 --- /dev/null +++ b/test-resources/example-proc-macro/src/lib.rs @@ -0,0 +1,23 @@ +extern crate proc_macro; + +use crate::proc_macro::TokenStream; + +#[proc_macro_derive(HelloMacro)] +pub fn hello_macro_derive(input: TokenStream) -> TokenStream { +} + +#[proc_macro] +pub fn sql(input: TokenStream) -> TokenStream { +} + +#[proc_macro_attribute] +pub fn route(attr: TokenStream, item: TokenStream) -> TokenStream { +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/test-resources/example-virtual-workspace/Cargo.toml b/test-resources/example-virtual-workspace/Cargo.toml new file mode 100644 index 00000000..f9c4362e --- /dev/null +++ b/test-resources/example-virtual-workspace/Cargo.toml @@ -0,0 +1,4 @@ +[workspace] +members = [ + "example-workspace-package", +] \ No newline at end of file diff --git a/test-resources/example-virtual-workspace/example-workspace-package/Cargo.toml b/test-resources/example-virtual-workspace/example-workspace-package/Cargo.toml new file mode 100644 index 00000000..1879b3a6 --- /dev/null +++ b/test-resources/example-virtual-workspace/example-workspace-package/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "example-workspace-package" +version = "0.1.0" +authors = ["Name "] +edition = "2018" + +[dependencies] diff --git a/test-resources/example-virtual-workspace/example-workspace-package/src/lib.rs b/test-resources/example-virtual-workspace/example-workspace-package/src/lib.rs new file mode 100644 index 00000000..e7fa1ec7 --- /dev/null +++ b/test-resources/example-virtual-workspace/example-workspace-package/src/lib.rs @@ -0,0 +1,23 @@ +extern crate proc_macro; + +use crate::proc_macro::TokenStream; + +#[proc_macro_derive(HelloMacro)] +pub fn hello_macro_derive(input: TokenStream) -> TokenStream { +} + +#[proc_macro] +pub fn sql(input: TokenStream) -> TokenStream { +} + +#[proc_macro_attribute] +pub fn route(attr: TokenStream, item: TokenStream) -> TokenStream { +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/test-resources/example-workspace/Cargo.lock b/test-resources/example-workspace/Cargo.lock new file mode 100644 index 00000000..d549cef1 --- /dev/null +++ b/test-resources/example-workspace/Cargo.lock @@ -0,0 +1,10 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "example-workspace" +version = "0.1.0" + +[[package]] +name = "example-workspace-package" +version = "0.1.0" + diff --git a/test-resources/example-workspace/Cargo.toml b/test-resources/example-workspace/Cargo.toml new file mode 100644 index 00000000..4838caf3 --- /dev/null +++ b/test-resources/example-workspace/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "example-workspace" +version = "0.1.0" +authors = ["Name "] +edition = "2018" + +[dependencies] + +[workspace] +members = [ + "example-workspace-package", +] \ No newline at end of file diff --git a/test-resources/example-workspace/example-workspace-package/Cargo.toml b/test-resources/example-workspace/example-workspace-package/Cargo.toml new file mode 100644 index 00000000..1879b3a6 --- /dev/null +++ b/test-resources/example-workspace/example-workspace-package/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "example-workspace-package" +version = "0.1.0" +authors = ["Name "] +edition = "2018" + +[dependencies] diff --git a/test-resources/example-workspace/example-workspace-package/src/lib.rs b/test-resources/example-workspace/example-workspace-package/src/lib.rs new file mode 100644 index 00000000..e7fa1ec7 --- /dev/null +++ b/test-resources/example-workspace/example-workspace-package/src/lib.rs @@ -0,0 +1,23 @@ +extern crate proc_macro; + +use crate::proc_macro::TokenStream; + +#[proc_macro_derive(HelloMacro)] +pub fn hello_macro_derive(input: TokenStream) -> TokenStream { +} + +#[proc_macro] +pub fn sql(input: TokenStream) -> TokenStream { +} + +#[proc_macro_attribute] +pub fn route(attr: TokenStream, item: TokenStream) -> TokenStream { +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/test-resources/example-workspace/src/lib.rs b/test-resources/example-workspace/src/lib.rs new file mode 100644 index 00000000..31e1bb20 --- /dev/null +++ b/test-resources/example-workspace/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +}