Commit graph

87 commits

Author SHA1 Message Date
Ed Page
7513b412fe fix(new): Print a note, rather than a comment, for more information
Fixes #12210
2024-01-29 15:38:04 -06:00
Ed Page
db54c040ae fix(new): Print a 'Creating', rather than 'Created' status
This has bothered me about `cargo new` and `cargo init` for a while that
the output is read backwards, for example:
```diff
--- i/tests/testsuite/cargo_init/path_contains_separator/stderr.log
+++ w/tests/testsuite/cargo_init/path_contains_separator/stderr.log
@@ -1,3 +1,3 @@
+    Creating binary (application) package
 warning: the path `[ROOT]/case/test:ing/.` contains invalid PATH characters (usually `:`, `;`, or `"`)
 It is recommended to use a different name to avoid problems.
-     Created binary (application) package
```
2024-01-29 15:29:10 -06:00
Ed Page
675224b3a0 test(config): Shift to config.toml 2024-01-26 13:40:46 -06:00
Weihang Lo
a3267bfa29
refactor(util-schemas): error type for restricted_names 2023-12-20 10:38:02 -05:00
bors
f5418fcfeb Auto merge of #12766 - shnaramn:WarnAboutNameCase, r=epage
Warn about crate name's format when creating new crate

### What does this PR try to resolve?
Warns about a crate's name during creation (`crate new ...`) if it doesn't follow the preferred snake_case format.

Fixes #2708

The warning message uses the language mentioned in [RFC 430](https://github.com/rust-lang/rfcs/blob/master/text/0430-finalizing-naming-conventions.md#general-naming-conventions).

### How should we test and review this PR?
Verified existing tests succeeded with updates.  Added new tests to verify fix.

### Additional information
The link to [API naming guidelines](https://rust-lang.github.io/api-guidelines/naming.html) was not used since it still stays `unclear` for naming convention for crates.
2023-10-23 17:17:58 +00:00
Ed Page
99f917a67e fix(help): Consistently use SCREAMING_CASE for value names
- We have some positional value names that are SCREAMING_CASE and some
  that aren't
- All of the value names for our flags are already SCREAMING_CASE
2023-10-17 16:47:44 -05:00
Shankar Mathiah Nanjundan
901018c3db Fixes #2708
Warns about not using snake_case or kebab-case format when creating new packages with `cargo new` command.
2023-10-16 23:39:19 -07:00
Charles Samborski
54ad4a01df fix(new): Don't ignore Cargo.lock for all package types
Following the default guidance to commit a lockfile, this updates
`cargo new` to do it by default.
2023-07-19 11:56:40 -05:00
Rob Ede
8183c31eec
chore: fix target in generated hg ignore file 2023-03-15 16:39:24 +00:00
Weihang Lo
c51c6bb6ac
chore: reflect to clap updates 2023-01-14 09:23:39 +00:00
RyanAD
82a92a203c Warn if project path contains an invalid PATH env character 2022-11-12 18:43:35 -07:00
Frank Yang
b98c534d57
fix: return non UTF-8 error message
Signed-off-by: Frank Yang <yangpoan@gmail.com>
2022-11-10 23:49:08 +08:00
Ed Page
5f30808d00 chore: Update tests for latest clap 2022-10-13 15:16:38 -05:00
Ed Page
96948f7a24 refactor(cli): Upgrade to clap v4 2022-09-28 13:32:14 -05:00
BlackHoleFox
b676088572 Update non-ASCII crate name warning message 2022-08-23 14:23:59 -05:00
merelymyself
3d21b14323 Guide new users to add use super::*; to mod test 2022-05-27 23:41:37 +08:00
merelymyself
73aa070687 Guide new users to add use super::*; 2022-05-24 20:27:58 +08:00
Weihang Lo
552b52a894
Test for cargo new/init autodetct and ignore file rules 2022-02-11 18:54:27 +08:00
Eric Holk
1683cd5eec Refactor create_empty_config to create_default_config 2022-01-19 08:45:03 -08:00
Eric Holk
40c51392dd Fix new::git_default_branch with different default
The test new::git_default_branch would fail if the current user had
already configured a different default branch.

This patch changes the test to first write a .gitconfig file with the
default branch set to master. This puts us in a state where we still
have the old default, and then the subsequent change to the config file
will make sure that config changes are still respected.
2022-01-18 14:51:21 -08:00
Ed Page
f17ecafc24 Upgrade to Clap 3
- One parser change found by `cargo_config::includes` is that clap 2
  would ignore any values after a `=` for flags.
  `cargo config --show-origin` is a flag but the test passed `--show-origin=yes` which
  happens to give the desired result for that test but is the same as
  `--show-origin=no` or `--show-origin=alien-invasion`.
- The parser now panics when accessing an undefined attribute but clap
  takes advantage of that for sharing code across commands that have
  different subsets of arguments defined.  I've extended clap so we can
  "look before you leap" and put the checks at the argument calls to
  start off with so its very clear what is tenuously shared.  This
  allows us to go in either direction in the future, either addressing
  how we are sharing between commands or by moving this down into the
  extension methods and pretending this clap feature doesn't exist
- On that topic, a test found clap-rs/clap#3263.  For now, there is a
  hack in clap.  Depending on how we fix that in clap for clap 4.0, we
  might need to re-address things in cargo.
- `value_of_os` now requires setting `allow_invalid_utf8`, otherwise it
  asserts.  To help catch this, I updated the argument definitions
  associated with lookups reported by:
  - `rg 'values?_os' src/`
  - `rg 'values?_of_os' src/`
- clap now reports `2` for usage errors, so we had to bypass clap's
  `exit` call to keep the same exit code.

BREAKING CHANGE: API now uses clap3
2022-01-05 19:54:54 -06:00
Eric Huss
88117505b8 Bump to 0.59.0 2021-10-22 07:53:17 -07:00
dswij
bd005850d8 Update test output for hint on project creation [bin] -> [[bin]] 2021-09-06 15:51:33 +08:00
Eric Huss
68753e2874 Temporarily move test lockfile_constant_during_new to nightly. 2021-08-31 22:44:34 -07:00
Eric Huss
e6a783acd4 Stabilize 2021 edition 2021-08-31 22:24:00 -07:00
hi-rustin
7d4b5dfdb1 Make library created with cargo new clippy happy
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2021-08-17 19:44:10 +08:00
Jade
160b7f1dac Test the generated manifest does not contain authors = 2021-03-22 13:39:18 -07:00
Jade
de45c6f97a Delete uses of the USER env var from tests 2021-03-22 13:39:18 -07:00
Jade
c685eb322b RFC 3052: Stop including authors field in manifests made by cargo new
See https://github.com/rust-lang/rust/issues/83227
2021-03-22 13:39:15 -07:00
bjorn3
f5a3d55983 Fix warnings of the new non_fmt_panic lint 2021-02-06 19:10:42 +01:00
Eric Huss
fdb8ea1e03 Add some extra help to cargo new and invalid package names. 2021-01-24 13:21:25 -08:00
bors
78beb3784f Auto merge of #8912 - aniljava:master, r=alexcrichton
Fixes #8783 , cargo new fails without a author name or email

If user can not be obtained from git or env variables $USER, new command defaults to empty author in generated Cargo.toml

Could not edit old PR(#8910 8783) as the original clone was deleted.
2020-12-03 15:14:39 +00:00
Anil P
a006347b2d Removed debug println! 2020-12-02 23:04:00 -06:00
Anil P
4787dd3acf rustfmt 2020-12-02 23:02:55 -06:00
Anil P
4eeadfb38c Explicitly removed USER env variables. 2020-12-02 22:59:40 -06:00
Anil P
fad16813a3 Removed debug println from earlier commit. 2020-12-02 12:39:29 -06:00
asdf
c3e01b8fe3 Fix test escaping __CARGO_TEST_ROOT 2020-12-01 21:58:32 -08:00
Anil P
917fc99fd5 Test cargo new with missing authors
- test case for missing name and email (author_without_user_or_email)
- test case for handling email only (finds_author_email_only)
2020-12-01 23:46:16 -06:00
Franz-Xaver Geiger
35b029c2ce Start searching git config at path of the new project
This lets `cargo new` follow `includeIf` blocks inside .gitignore.

Fixes #8882
2020-11-23 20:43:57 +01:00
Eric Huss
0be75d2edc Update git2. 2020-10-13 18:13:25 -07:00
Weihang Lo
c6fcb0e2ef
Fix unintenional newline in stderr assertion 2020-09-11 01:02:59 +08:00
Weihang Lo
2fbce89dd6
Rephrase message of restricted crate name 2020-09-11 00:39:51 +08:00
Weihang Lo
c00ad7922d
Fix test for windows reserved filename error message 2020-09-04 09:18:47 +08:00
Weihang Lo
9cda385ab3
Test for --name hint 2020-09-04 08:39:13 +08:00
Eric Huss
4ae79d2ffd Use fs helpers instead of File functions. 2020-04-17 07:56:16 -07:00
Eric Huss
95008f91e5 Try to better handle restricted crate names. 2020-03-02 16:04:24 -08:00
bors
abba15f95a Auto merge of #7667 - giraffate:add_test_for_name_when_cargo_new, r=alexcrichton
Add test for `NAME` environment variable when `cargo new`

Looks like there was no test for `NAME` environment variable when `cargo new`.
2019-12-06 01:14:07 +00:00
Takayuki Nakata
2fb90adc73 Add test for NAME environment variable when cargo new 2019-12-06 09:30:13 +09:00
Takayuki Nakata
058937f018 Add test for GIT_COMMITTER_EMAIL when cargo new
There was no test for `GIT_COMMITER_EMAIL`, so I add the test for
this. In addition, I update the name of some tests.
2019-12-05 12:39:10 +09:00
Josh Triplett
997a6d5ab9 Stop ignoring .rs.bk files; rustfmt hasn't generated them in years
cargo currently generates a .gitignore file that ignores .rs.bk files,
historically because rustfmt would sometimes generate such files.
However, rustfmt and cargo fmt don't generate backup files by default
(only when requested), and even when requested, they generate .bk files,
not .rs.bk files (as of rustfmt commit
fad903fd14ad0df045dc574cac0717312860c380 in 2017). And nobody seems to
have noticed or complained since then, likely because rustfmt doesn't
generate backup files by default.

rustfmt also plans to deprecate the --backup option entirely, in rustfmt
2.0, and instead always rely on version control to track changes.

In addition, these types of ignores, just like ignores of editor backup
files, don't belong in .gitignore; they belong in people's personal
ignore files, such as ~/.config/git/ignore.  See
https://julien.danjou.info/properly-managing-your-gitignore/ for further
explanation of that.

Given all three of those factors, drop the code to add **/*.rs.bk to
.gitignore, and update tests accordingly.
2019-12-02 12:40:38 -08:00