diff --git a/checks/cleanCargoTomlTests/complex-underscores/expected-cargoTomlAggressive.toml b/checks/cleanCargoTomlTests/complex-underscores/expected-cargoTomlAggressive.toml new file mode 100644 index 00000000..e634b69d --- /dev/null +++ b/checks/cleanCargoTomlTests/complex-underscores/expected-cargoTomlAggressive.toml @@ -0,0 +1,132 @@ +cargo_features = ["some unstable features"] +[[bench]] +edition = "2015" +harness = true +name = "bench1" +path = "src/bench1.rs" +proc_macro = false + +[[bench]] +edition = "2018" +harness = false +name = "bench2" +path = "src/bench2.rs" +proc_macro = false + +[[bin]] +edition = "2015" +harness = true +name = "bin1" +path = "src/bin1.rs" +proc_macro = false + +[[bin]] +edition = "2018" +harness = true +name = "bin2" +path = "src/bin2.rs" +proc_macro = false + +[[example]] +crate_type = ["staticlib"] +edition = "2015" +harness = true +name = "example1" +path = "src/example1.rs" +proc_macro = false + +[[example]] +edition = "2018" +harness = true +name = "example2" +path = "src/example2.rs" +proc_macro = false + +[[test]] +edition = "2015" +harness = true +name = "test1" +path = "src/test1.rs" +proc_macro = false + +[[test]] +edition = "2018" +harness = true +name = "test2" +path = "src/test2.rs" +proc_macro = false + +[build_dependencies.corge] +version = "6" + +[dependencies] +foo = "1" + +[dependencies.bar] +features = ["bar_feature", "bar_another_feature"] +version = "2" + +[dependencies.baz] +features = ["baz_feature", "baz_feature2"] +version = "3" + +[dev_dependencies] +qux = "4" + +[dev_dependencies.zuul] +version = "5" + +[features] +barfeature = ["foofeature"] +foofeature = [] + +[lib] +crate_type = ["lib", "rlib"] +edition = "2021" +harness = true +name = "foo" +path = "src/lib.rs" +proc_macro = false + +[package] +edition = "2021" +name = "some name" +resolver = "2" +version = "1.2.3" +workspace = "some/path/to/workspace" + +[patch.crates_io] +[patch.crates_io.bar] +path = "my/local/bar" + +[patch.crates_io.foo] +git = "https://github.com/example/foo" + +[profile] +[profile.dev] +opt_level = 1 +overflow_checks = false + +[profile.release] +opt_level = 2 +overflow_checks = true + +[replace] +[replace."bar3:1.0.2"] +path = "my/local/bar3" + +[replace."foo2:0.1.0"] +git = "https://github.com/example/foo2" + +[target] +[target."cfg(target_arch = \"x86\")".dependencies] +garply = "8" + +[target."cfg(unix)".dependencies] +grault = "7" + +[workspace] +resolver = "2" +default_members = ["path/to/member2", "path/to/member3/foo"] +exclude = ["crates/foo", "path/to/other"] +members = ["member1", "path/to/member2", "crates/*"] diff --git a/checks/cleanCargoTomlTests/complex/expected-cargoTomlAggressive.toml b/checks/cleanCargoTomlTests/complex/expected-cargoTomlAggressive.toml new file mode 100644 index 00000000..e1e0be31 --- /dev/null +++ b/checks/cleanCargoTomlTests/complex/expected-cargoTomlAggressive.toml @@ -0,0 +1,132 @@ +cargo-features = ["some unstable features"] +[[bench]] +edition = "2015" +harness = true +name = "bench1" +path = "src/bench1.rs" +proc-macro = false + +[[bench]] +edition = "2018" +harness = true +name = "bench2" +path = "src/bench2.rs" +proc-macro = false + +[[bin]] +edition = "2015" +harness = false +name = "bin1" +path = "src/bin1.rs" +proc-macro = false + +[[bin]] +edition = "2018" +harness = true +name = "bin2" +path = "src/bin2.rs" +proc-macro = false + +[[example]] +crate-type = ["staticlib"] +edition = "2015" +harness = true +name = "example1" +path = "src/example1.rs" +proc-macro = false + +[[example]] +edition = "2018" +harness = true +name = "example2" +path = "src/example2.rs" +proc-macro = false + +[[test]] +edition = "2015" +harness = true +name = "test1" +path = "src/test1.rs" +proc-macro = false + +[[test]] +edition = "2018" +harness = true +name = "test2" +path = "src/test2.rs" +proc-macro = false + +[build-dependencies.corge] +version = "6" + +[dependencies] +foo = "1" + +[dependencies.bar] +features = ["bar-feature", "bar-another-feature"] +version = "2" + +[dependencies.baz] +features = ["baz-feature", "baz-feature2"] +version = "3" + +[dev-dependencies] +qux = "4" + +[dev-dependencies.zuul] +version = "5" + +[features] +barfeature = ["foofeature"] +foofeature = [] + +[lib] +crate-type = ["lib", "rlib"] +edition = "2021" +harness = true +name = "foo" +path = "src/lib.rs" +proc-macro = false + +[package] +edition = "2021" +name = "some name" +resolver = "2" +version = "1.2.3" +workspace = "some/path/to/workspace" + +[patch.crates-io] +[patch.crates-io.bar] +path = "my/local/bar" + +[patch.crates-io.foo] +git = "https://github.com/example/foo" + +[profile] +[profile.dev] +opt-level = 1 +overflow-checks = false + +[profile.release] +opt-level = 2 +overflow-checks = true + +[replace] +[replace."bar3:1.0.2"] +path = "my/local/bar3" + +[replace."foo2:0.1.0"] +git = "https://github.com/example/foo2" + +[target] +[target."cfg(target_arch = \"x86\")".dependencies] +garply = "8" + +[target."cfg(unix)".dependencies] +grault = "7" + +[workspace] +resolver = "2" +default-members = ["path/to/member2", "path/to/member3/foo"] +exclude = ["crates/foo", "path/to/other"] +members = ["member1", "path/to/member2", "crates/*"] diff --git a/checks/cleanCargoTomlTests/default.nix b/checks/cleanCargoTomlTests/default.nix index b06e451d..dfc32659 100644 --- a/checks/cleanCargoTomlTests/default.nix +++ b/checks/cleanCargoTomlTests/default.nix @@ -1,5 +1,6 @@ { cleanCargoToml, + filters, lib, linkFarmFromDrvs, remarshal, @@ -9,20 +10,22 @@ let cmpCleanCargoToml = - name: path: + folderName: path: filterName: filter: let cleaned = cleanCargoToml { cargoToml = path + "/Cargo.toml"; + cleanCargoTomlFilter = filter; }; - cleanedToml = writeTOML "cleaned.toml" cleaned; - expected = path + "/expected.toml"; - + cleanedToml = writeTOML "cleaned-${folderName}-${filterName}.toml" cleaned; + expectedPathSpecific = path + "/expected-${filterName}.toml"; + expected = + if lib.pathExists expectedPathSpecific then expectedPathSpecific else path + "/expected.toml"; # 23.05 has remarshal 0.14 which sorts keys by default # starting with version 0.16 ordering is preserved unless # --sort-keys is specified sortKeys = lib.optionalString (lib.strings.versionAtLeast remarshal.version "0.16.0") "--sort-keys"; in - runCommand "compare-${name}" { } '' + runCommand "compare-${folderName}-${filterName}" { } '' function reformat { ${remarshal}/bin/remarshal ${sortKeys} -i "$1" --of toml } @@ -30,12 +33,17 @@ let diff <(reformat ${expected}) <(reformat ${cleanedToml}) touch $out ''; + cmpAllFilters = + name: path: + lib.mapAttrsToList (filterName: filter: cmpCleanCargoToml name path filterName filter) filters; + + testMatrix = { + barebones = ./barebones; + complex = ./complex; + # https://github.com/ipetkov/crane/issues/610 + complex-underscores = ./complex-underscores; + # https://github.com/ipetkov/crane/issues/800 + proc-macro = ./proc-macro; + }; in -linkFarmFromDrvs "cleanCargoToml" [ - (cmpCleanCargoToml "barebones" ./barebones) - (cmpCleanCargoToml "complex" ./complex) - # https://github.com/ipetkov/crane/issues/610 - (cmpCleanCargoToml "complex-underscores" ./complex-underscores) - #https://github.com/ipetkov/crane/issues/800 - (cmpCleanCargoToml "proc-macro" ./proc-macro) -] +linkFarmFromDrvs "cleanCargoToml" (lib.concatLists (lib.mapAttrsToList cmpAllFilters testMatrix)) diff --git a/lib/filters/cargoTomlAggressive.nix b/lib/filters/cargoTomlAggressive.nix index 8494a7e3..3dadc389 100644 --- a/lib/filters/cargoTomlAggressive.nix +++ b/lib/filters/cargoTomlAggressive.nix @@ -53,6 +53,6 @@ let ++ (pathsToKeepPerTarget "test") ++ (pathsToKeepPerTarget "bench"); - cargoTomlAggressive = path: builtins.any (lib.lists.hasPrefix path) pathsToKeep; + cargoTomlAggressive = path: builtins.any (p: lib.lists.hasPrefix path p || lib.lists.hasPrefix p path) pathsToKeep; in cargoTomlAggressive