]> git.proxmox.com Git - cargo.git/commitdiff
Change the default edition for `cargo new` to 2018
authorAlex Crichton <alex@alexcrichton.com>
Fri, 7 Sep 2018 00:01:20 +0000 (17:01 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 7 Sep 2018 00:01:20 +0000 (17:01 -0700)
As it says on the tin! Some tests were updated to explicitly pass 2015 so they
can continue to work on stable, and otherwise `cargo new` should now by default
generate a 2018 project.

src/cargo/ops/cargo_new.rs
tests/testsuite/init.rs
tests/testsuite/new.rs

index 3351466d681f5a435873bc7cc4ec52fd17620faf..dad9253035551825e28aafcac9fed5f75416f0ae 100644 (file)
@@ -535,18 +535,16 @@ path = {}
             r#"[package]
 name = "{}"
 version = "0.1.0"
-authors = [{}]{}
+authors = [{}]
+edition = {}
 
 [dependencies]
 {}"#,
             name,
             toml::Value::String(author),
             match opts.edition {
-                Some(edition) => {
-                    let edition = toml::Value::String(edition.to_string());
-                    format!("\nedition = {}", edition)
-                }
-                None => String::new(),
+                Some(edition) => toml::Value::String(edition.to_string()),
+                None => toml::Value::String("2018".to_string()),
             },
             cargotoml_path_specifier
         ).as_bytes(),
index 2f1e228f6fd9c437593645b40b7220b230a8eb9e..c4f281ad65be5923b12f77cd746ceb9e06436b02 100644 (file)
@@ -13,7 +13,7 @@ fn cargo_process(s: &str) -> Execs {
 
 #[test]
 fn simple_lib() {
-    cargo_process("init --lib --vcs none")
+    cargo_process("init --lib --vcs none --edition 2015")
         .env("USER", "foo")
         .with_stderr("[CREATED] library project")
         .run();
@@ -29,7 +29,7 @@ fn simple_lib() {
 fn simple_bin() {
     let path = paths::root().join("foo");
     fs::create_dir(&path).unwrap();
-    cargo_process("init --bin --vcs none")
+    cargo_process("init --bin --vcs none --edition 2015")
         .env("USER", "foo")
         .cwd(&path)
         .with_stderr("[CREATED] binary (application) project")
index 7d524544b3035b9e1358c70fd7cc0af2624524dc..3f09e3af16639b76a19d8449e76fef49dc98bca1 100644 (file)
@@ -14,7 +14,7 @@ fn create_empty_gitconfig() {
 
 #[test]
 fn simple_lib() {
-    cargo_process("new --lib foo --vcs none")
+    cargo_process("new --lib foo --vcs none --edition 2015")
         .env("USER", "foo")
         .with_stderr("[CREATED] library `foo` project")
         .run();
@@ -47,7 +47,7 @@ mod tests {
 
 #[test]
 fn simple_bin() {
-    cargo_process("new --bin foo")
+    cargo_process("new --bin foo --edition 2015")
         .env("USER", "foo")
         .with_stderr("[CREATED] binary (application) `foo` project")
         .run();
@@ -75,7 +75,7 @@ fn both_lib_and_bin() {
 
 #[test]
 fn simple_git() {
-    cargo_process("new --lib foo").env("USER", "foo").run();
+    cargo_process("new --lib foo --edition 2015").env("USER", "foo").run();
 
     assert!(paths::root().is_dir());
     assert!(paths::root().join("foo/Cargo.toml").is_file());
@@ -474,6 +474,15 @@ fn new_with_edition_2018() {
     assert!(manifest.contains("edition = \"2018\""));
 }
 
+#[test]
+fn new_default_edition() {
+    cargo_process("new foo")
+        .env("USER", "foo")
+        .run();
+    let manifest = fs::read_to_string(paths::root().join("foo/Cargo.toml")).unwrap();
+    assert!(manifest.contains("edition = \"2018\""));
+}
+
 #[test]
 fn new_with_bad_edition() {
     cargo_process("new --edition something_else foo")