Skip to content

Commit

Permalink
Move template into internal directory
Browse files Browse the repository at this point in the history
Partially revert #355
  • Loading branch information
smoelius committed Jun 29, 2022
1 parent a033d5b commit 99de0f6
Show file tree
Hide file tree
Showing 32 changed files with 87 additions and 62 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,14 @@ jobs:
run: cargo install --path ./dylint-link

- name: Test
run: cargo test --workspace --all-features -- --nocapture
run: |
if [[ ${{ matrix.environment }} != 'windows-latest' ]]; then
cargo test --workspace --all-features -- --nocapture
else
cargo test --workspace --exclude dylint_internal --all-features -- --nocapture
cargo clean
cargo test -p dylint_internal --all-features -- --nocapture
fi
- name: Test example documentation
# smoelius: The `cdylib` -> `lib` trick is due to @MinerSebas.
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 1 addition & 21 deletions cargo-dylint/tests/dylint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use cargo_metadata::{Dependency, Metadata, MetadataCommand};
use cargo_metadata::{Dependency, Metadata};
use dylint_internal::cargo::current_metadata;
use lazy_static::lazy_static;
use regex::Regex;
Expand Down Expand Up @@ -47,26 +47,6 @@ fn versions_are_exact_and_match() {
}
}

#[test]
fn template_has_initial_version() {
let metadata = MetadataCommand::new()
.current_dir(
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("..")
.join("examples")
.join("other")
.join("template"),
)
.no_deps()
.exec()
.unwrap();
if let [package] = metadata.packages.as_slice() {
assert_eq!(package.version.to_string(), "0.1.0");
} else {
panic!();
}
}

#[test]
fn workspace_and_cargo_dylint_readmes_are_equivalent() {
let workspace_readme = readme_contents(".").unwrap();
Expand Down
15 changes: 7 additions & 8 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The example libraries are separated into the following three categories:

- [general] - applicable to most projects
- [restriction] - would likely be considered "restriction lints" by [Clippy], e.g., reflect concerns not necessarily held by all authors
- [other] - used, e.g., for testing purposes
- [testing] - used only for testing purposes

## General

Expand All @@ -27,13 +27,12 @@ The example libraries are separated into the following three categories:
| [`suboptimal_pattern`](./restriction/suboptimal_pattern) | A lint to check for patterns that could perform additional destructuring |
| [`try_io_result`](./restriction/try_io_result) | A lint to check for the `?` operator applied to `std::io::Result` |

## Other
## Testing

| Example | Description |
| -------------------------------- | ------------------------------------------------------ |
| [`clippy`](./other/clippy) | All of the Clippy lints as a Dylint library |
| [`straggler`](./other/straggler) | A lint that uses an old toolchain for testing purposes |
| [`template`](./other/template) | decription goes here |
| Example | Description |
| ---------------------------------- | ------------------------------------------------------ |
| [`clippy`](./testing/clippy) | All of the Clippy lints as a Dylint library |
| [`straggler`](./testing/straggler) | A lint that uses an old toolchain for testing purposes |

**Notes**

Expand All @@ -46,5 +45,5 @@ The example libraries are separated into the following three categories:

[clippy]: https://github.com/rust-lang/rust-clippy#clippy
[general]: #general
[other]: #other
[restriction]: #restriction
[testing]: #testing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ log = "0.4.17"
rust-embed = { version = "6.4.0", features = ["include-exclude"] }
sedregex = "0.2.5"
walkdir = "2.3.2"

[dev-dependencies]
toml_edit = "0.14.4"
74 changes: 50 additions & 24 deletions internal/src/packaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use std::{
};

#[derive(RustEmbed)]
#[folder = "../examples/other/template"]
#[folder = "template"]
#[exclude = "Cargo.lock"]
#[exclude = "target/*"]
struct Template;

pub fn new_template(to: &Path) -> Result<()> {
for path in Template::iter() {
let to_path = to.join(&*path);
let to_path = to.join(path.trim_end_matches('~'));
let parent = to_path
.parent()
.ok_or_else(|| anyhow!("Could not get parent directory"))?;
Expand Down Expand Up @@ -107,26 +107,52 @@ pub fn use_local_packages(path: &Path) -> Result<()> {
Ok(())
}

#[test]
fn template_includes_only_whitelisted_paths() {
const PATHS: [&str; 8] = [
".cargo/config.toml",
".gitignore",
"Cargo.toml",
"README.md",
"rust-toolchain",
"src/lib.rs",
"ui/main.rs",
"ui/main.stderr",
];

let mut paths_sorted = PATHS.to_vec();
paths_sorted.sort_unstable();
assert_eq!(paths_sorted, PATHS);

let paths = Template::iter()
.filter(|path| PATHS.binary_search(&&**path).is_err())
.collect::<Vec<_>>();

assert!(paths.is_empty(), "found {:#?}", paths);
#[cfg(test)]
mod test {
use super::*;
use std::fs::read_to_string;
use toml_edit::{Document, Item};

#[test]
fn template_includes_only_whitelisted_paths() {
const PATHS: [&str; 8] = [
".cargo/config.toml",
".gitignore",
"Cargo.toml~",
"README.md",
"rust-toolchain",
"src/lib.rs",
"ui/main.rs",
"ui/main.stderr",
];

let mut paths_sorted = PATHS.to_vec();
paths_sorted.sort_unstable();
assert_eq!(paths_sorted, PATHS);

let paths = Template::iter()
.filter(|path| PATHS.binary_search(&&**path).is_err())
.collect::<Vec<_>>();

assert!(paths.is_empty(), "found {:#?}", paths);
}

#[test]
fn template_has_initial_version() {
let file = read_to_string(
&Path::new(env!("CARGO_MANIFEST_DIR"))
.join("template")
.join("Cargo.toml~"),
)
.unwrap();
let document = file.parse::<Document>().unwrap();
let version = document
.as_table()
.get("package")
.and_then(Item::as_table)
.and_then(|table| table.get("version"))
.and_then(Item::as_str)
.unwrap();
assert_eq!(version, "0.1.0");
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ crate-type = ["cdylib"]

[dependencies]
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "b312ad7d0cf0f30be2bd4658b71a3520a2e76709" }
dylint_linting = "2.0.6"
dylint_linting = "2.0.7"
if_chain = "1.0.2"

[dev-dependencies]
dylint_testing = "2.0.6"
dylint_testing = "2.0.7"

[workspace]

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 1 addition & 4 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ EXAMPLE_DIRS="$(find examples -mindepth 2 -maxdepth 2 -type d)"

# smoelius: Remove `straggler`, as it is used only for testing purposes. Also, it uses a different
# toolchain than the other examples.
EXAMPLE_DIRS="$(echo "$EXAMPLE_DIRS" | sed 's,\<examples/other/straggler\>[[:space:]]*,,')"

# smoelius: Remove `template`, as it does not use workspace metadata like the other libraries.
EXAMPLE_DIRS="$(echo "$EXAMPLE_DIRS" | sed 's,\<examples/other/template\>[[:space:]]*,,')"
EXAMPLE_DIRS="$(echo "$EXAMPLE_DIRS" | sed 's,\<examples/testing/straggler\>[[:space:]]*,,')"

DIRS=". driver $EXAMPLE_DIRS"

Expand Down
2 changes: 1 addition & 1 deletion scripts/update_example_READMEs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cd "$WORKSPACE"/examples

TMP="$(mktemp)"

CATEGORIES=(general restriction other)
CATEGORIES=(general restriction testing)
LISTED=

IFS=
Expand Down
4 changes: 4 additions & 0 deletions scripts/update_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ REQ="$(echo "$VERSION" | sed 's/"/"=/')"
find . -name Cargo.toml -exec sed -i "/^dylint/{
s/^\(.*\)\<version = \"[^\"]*\"\(.*\)$/\1$REQ\2/
}" {} \;

# smoelius: `template` must be handled specially because it does not use the `version = "..."`
# syntax.
sed -i "s/^\(dylint_[^ ]*\) = \"[^\"]*\"$/\1 = \"$1\"/" internal/template/Cargo.toml
10 changes: 9 additions & 1 deletion scripts/upgrade_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cd "$WORKSPACE"

CARGO_DYLINT='timeout 10m cargo run -p cargo-dylint -- dylint'

for EXAMPLE in examples/*/*; do
for EXAMPLE in examples/*/* internal/template; do
if [[ ! -d "$EXAMPLE" ]]; then
continue
fi
Expand Down Expand Up @@ -53,5 +53,13 @@ for EXAMPLE in examples/*/*; do
fi
fi

if [[ "$EXAMPLE" = 'internal/template' ]]; then
mv "$EXAMPLE"/Cargo.toml~ "$EXAMPLE"/Cargo.toml
fi

$CARGO_DYLINT --upgrade "$EXAMPLE" --bisect

if [[ "$EXAMPLE" = 'internal/template' ]]; then
mv "$EXAMPLE"/Cargo.toml "$EXAMPLE"/Cargo.toml~
fi
done

0 comments on commit 99de0f6

Please sign in to comment.