Skip to content

Commit 3f136f7

Browse files
authored
[nextest-runner] reorganize config directory (#2496)
The config directory has been a mess for a long time. Here's an attempt to organize it into a few parts and make it easier to understand.
1 parent 5cb3b33 commit 3f136f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+340
-237
lines changed

cargo-nextest/src/dispatch.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ use nextest_runner::{
1818
RustcCli,
1919
cargo_config::{CargoConfigs, EnvironmentMap, TargetTriple},
2020
config::{
21-
ConfigExperimental, EarlyProfile, EvaluatableProfile, MaxFail, NextestConfig,
22-
NextestVersionConfig, NextestVersionEval, RetryPolicy, TestGroup, TestThreads,
23-
ToolConfigFile, VersionOnlyConfig, get_num_cpus,
21+
core::{
22+
ConfigExperimental, EarlyProfile, EvaluatableProfile, NextestConfig,
23+
NextestVersionConfig, NextestVersionEval, ToolConfigFile, VersionOnlyConfig,
24+
get_num_cpus,
25+
},
26+
elements::{MaxFail, RetryPolicy, TestGroup, TestThreads},
2427
},
2528
double_spawn::DoubleSpawnInfo,
2629
errors::{TargetTripleError, WriteTestListError},

nextest-runner/src/config/config_impl.rs renamed to nextest-runner/src/config/core/imp.rs

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
// Copyright (c) The nextest Contributors
22
// SPDX-License-Identifier: MIT OR Apache-2.0
33

4-
use super::{
5-
ArchiveConfig, CompiledByProfile, CompiledData, CompiledDefaultFilter, ConfigExperimental,
6-
CustomTestGroup, DefaultJunitImpl, DeserializedOverride, DeserializedProfileScriptConfig,
7-
GlobalTimeout, JunitConfig, JunitImpl, MaxFail, NextestVersionDeserialize, RetryPolicy,
8-
ScriptConfig, ScriptId, SettingSource, SetupScripts, SlowTimeout, TestGroup, TestGroupConfig,
9-
TestSettings, TestThreads, ThreadsRequired, ToolConfigFile, leak_timeout::LeakTimeout,
10-
};
4+
use super::{NextestVersionDeserialize, ToolConfigFile};
115
use crate::{
12-
config::{ListSettings, ProfileScriptType, ScriptInfo, SetupScriptConfig},
6+
config::{
7+
core::ConfigExperimental,
8+
elements::{
9+
ArchiveConfig, CustomTestGroup, DefaultJunitImpl, GlobalTimeout, JunitConfig,
10+
JunitImpl, LeakTimeout, MaxFail, RetryPolicy, SlowTimeout, TestGroup, TestGroupConfig,
11+
TestThreads, ThreadsRequired, deserialize_fail_fast, deserialize_leak_timeout,
12+
deserialize_retry_policy, deserialize_slow_timeout,
13+
},
14+
overrides::{
15+
CompiledByProfile, CompiledData, CompiledDefaultFilter, DeserializedOverride,
16+
ListSettings, SettingSource, TestSettings,
17+
},
18+
scripts::{
19+
DeserializedProfileScriptConfig, ProfileScriptType, ScriptConfig, ScriptId, ScriptInfo,
20+
SetupScriptConfig, SetupScripts,
21+
},
22+
},
1323
errors::{
1424
ConfigParseError, ConfigParseErrorKind, ProfileListScriptUsesRunFiltersError,
1525
ProfileNotFound, ProfileScriptErrors, ProfileUnknownScriptError,
@@ -206,7 +216,7 @@ impl NextestConfig {
206216
/// Contains the default config as a TOML file.
207217
///
208218
/// Repository-specific configuration is layered on top of the default config.
209-
pub const DEFAULT_CONFIG: &'static str = include_str!("../../default-config.toml");
219+
pub const DEFAULT_CONFIG: &'static str = include_str!("../../../default-config.toml");
210220

211221
/// Environment configuration uses this prefix, plus a _.
212222
pub const ENVIRONMENT_PREFIX: &'static str = "NEXTEST";
@@ -840,19 +850,19 @@ impl NextestConfig {
840850

841851
/// The state of nextest profiles before build platforms have been applied.
842852
#[derive(Clone, Debug, Default)]
843-
pub(super) struct PreBuildPlatform {}
853+
pub(in crate::config) struct PreBuildPlatform {}
844854

845855
/// The state of nextest profiles after build platforms have been applied.
846856
#[derive(Clone, Debug)]
847857
pub(crate) struct FinalConfig {
848858
// Evaluation result for host_spec on the host platform.
849-
pub(super) host_eval: bool,
859+
pub(in crate::config) host_eval: bool,
850860
// Evaluation result for target_spec corresponding to tests that run on the host platform (e.g.
851861
// proc-macro tests).
852-
pub(super) host_test_eval: bool,
862+
pub(in crate::config) host_test_eval: bool,
853863
// Evaluation result for target_spec corresponding to tests that run on the target platform
854864
// (most regular tests).
855-
pub(super) target_eval: bool,
865+
pub(in crate::config) target_eval: bool,
856866
}
857867

858868
/// A nextest profile that can be obtained without identifying the host and
@@ -868,7 +878,7 @@ pub struct EarlyProfile<'cfg> {
868878
// This is ordered because the scripts are used in the order they're defined.
869879
scripts: &'cfg ScriptConfig,
870880
// Invariant: `compiled_data.default_filter` is always present.
871-
pub(super) compiled_data: CompiledData<PreBuildPlatform>,
881+
pub(in crate::config) compiled_data: CompiledData<PreBuildPlatform>,
872882
}
873883

874884
impl<'cfg> EarlyProfile<'cfg> {
@@ -935,7 +945,7 @@ pub struct EvaluatableProfile<'cfg> {
935945
// This is ordered because the scripts are used in the order they're defined.
936946
scripts: &'cfg ScriptConfig,
937947
// Invariant: `compiled_data.default_filter` is always present.
938-
pub(super) compiled_data: CompiledData<FinalConfig>,
948+
pub(in crate::config) compiled_data: CompiledData<FinalConfig>,
939949
// The default filter that's been resolved after considering overrides (i.e.
940950
// platforms).
941951
resolved_default_filter: CompiledDefaultFilter,
@@ -1099,13 +1109,13 @@ impl<'cfg> EvaluatableProfile<'cfg> {
10991109
}
11001110

11011111
#[cfg(test)]
1102-
pub(super) fn custom_profile(&self) -> Option<&'cfg CustomProfileImpl> {
1112+
pub(in crate::config) fn custom_profile(&self) -> Option<&'cfg CustomProfileImpl> {
11031113
self.custom_profile
11041114
}
11051115
}
11061116

11071117
#[derive(Clone, Debug)]
1108-
pub(super) struct NextestConfigImpl {
1118+
pub(in crate::config) struct NextestConfigImpl {
11091119
store: StoreConfigImpl,
11101120
test_groups: BTreeMap<CustomTestGroup, TestGroupConfig>,
11111121
scripts: ScriptConfig,
@@ -1133,11 +1143,13 @@ impl NextestConfigImpl {
11331143
.chain(std::iter::once(NextestConfig::DEFAULT_PROFILE))
11341144
}
11351145

1136-
pub(super) fn default_profile(&self) -> &DefaultProfileImpl {
1146+
pub(in crate::config) fn default_profile(&self) -> &DefaultProfileImpl {
11371147
&self.default_profile
11381148
}
11391149

1140-
pub(super) fn other_profiles(&self) -> impl Iterator<Item = (&str, &CustomProfileImpl)> {
1150+
pub(in crate::config) fn other_profiles(
1151+
&self,
1152+
) -> impl Iterator<Item = (&str, &CustomProfileImpl)> {
11411153
self.other_profiles
11421154
.iter()
11431155
.map(|(key, value)| (key.as_str(), value))
@@ -1205,7 +1217,7 @@ struct StoreConfigImpl {
12051217
}
12061218

12071219
#[derive(Clone, Debug)]
1208-
pub(super) struct DefaultProfileImpl {
1220+
pub(in crate::config) struct DefaultProfileImpl {
12091221
default_filter: String,
12101222
test_threads: TestThreads,
12111223
threads_required: ThreadsRequired,
@@ -1270,26 +1282,26 @@ impl DefaultProfileImpl {
12701282
}
12711283
}
12721284

1273-
pub(super) fn default_filter(&self) -> &str {
1285+
pub(in crate::config) fn default_filter(&self) -> &str {
12741286
&self.default_filter
12751287
}
12761288

1277-
pub(super) fn overrides(&self) -> &[DeserializedOverride] {
1289+
pub(in crate::config) fn overrides(&self) -> &[DeserializedOverride] {
12781290
&self.overrides
12791291
}
12801292

1281-
pub(super) fn setup_scripts(&self) -> &[DeserializedProfileScriptConfig] {
1293+
pub(in crate::config) fn setup_scripts(&self) -> &[DeserializedProfileScriptConfig] {
12821294
&self.scripts
12831295
}
12841296
}
12851297

12861298
#[derive(Clone, Debug, Deserialize)]
12871299
#[serde(rename_all = "kebab-case")]
1288-
pub(super) struct CustomProfileImpl {
1300+
pub(in crate::config) struct CustomProfileImpl {
12891301
/// The default set of tests run by `cargo nextest run`.
12901302
#[serde(default)]
12911303
default_filter: Option<String>,
1292-
#[serde(default, deserialize_with = "super::deserialize_retry_policy")]
1304+
#[serde(default, deserialize_with = "deserialize_retry_policy")]
12931305
retries: Option<RetryPolicy>,
12941306
#[serde(default)]
12951307
test_threads: Option<TestThreads>,
@@ -1308,14 +1320,14 @@ pub(super) struct CustomProfileImpl {
13081320
#[serde(
13091321
default,
13101322
rename = "fail-fast",
1311-
deserialize_with = "super::deserialize_fail_fast"
1323+
deserialize_with = "deserialize_fail_fast"
13121324
)]
13131325
max_fail: Option<MaxFail>,
1314-
#[serde(default, deserialize_with = "super::deserialize_slow_timeout")]
1326+
#[serde(default, deserialize_with = "deserialize_slow_timeout")]
13151327
slow_timeout: Option<SlowTimeout>,
13161328
#[serde(default)]
13171329
global_timeout: Option<GlobalTimeout>,
1318-
#[serde(default, deserialize_with = "super::deserialize_leak_timeout")]
1330+
#[serde(default, deserialize_with = "deserialize_leak_timeout")]
13191331
leak_timeout: Option<LeakTimeout>,
13201332
#[serde(default)]
13211333
overrides: Vec<DeserializedOverride>,
@@ -1329,27 +1341,27 @@ pub(super) struct CustomProfileImpl {
13291341

13301342
impl CustomProfileImpl {
13311343
#[cfg(test)]
1332-
pub(super) fn test_threads(&self) -> Option<TestThreads> {
1344+
pub(in crate::config) fn test_threads(&self) -> Option<TestThreads> {
13331345
self.test_threads
13341346
}
13351347

1336-
pub(super) fn default_filter(&self) -> Option<&str> {
1348+
pub(in crate::config) fn default_filter(&self) -> Option<&str> {
13371349
self.default_filter.as_deref()
13381350
}
13391351

1340-
pub(super) fn overrides(&self) -> &[DeserializedOverride] {
1352+
pub(in crate::config) fn overrides(&self) -> &[DeserializedOverride] {
13411353
&self.overrides
13421354
}
13431355

1344-
pub(super) fn scripts(&self) -> &[DeserializedProfileScriptConfig] {
1356+
pub(in crate::config) fn scripts(&self) -> &[DeserializedProfileScriptConfig] {
13451357
&self.scripts
13461358
}
13471359
}
13481360

13491361
#[cfg(test)]
13501362
mod tests {
13511363
use super::*;
1352-
use crate::config::test_helpers::*;
1364+
use crate::config::utils::test_helpers::*;
13531365
use camino_tempfile::tempdir;
13541366
use iddqd::{IdHashItem, IdHashMap, id_hash_map, id_upcast};
13551367

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) The nextest Contributors
2+
// SPDX-License-Identifier: MIT OR Apache-2.0
3+
4+
//! Core configuration types.
5+
//!
6+
//! This module contains core configuration logic for nextest.
7+
8+
mod identifier;
9+
mod imp;
10+
mod nextest_version;
11+
mod tool_config;
12+
13+
pub use identifier::*;
14+
pub use imp::*;
15+
pub use nextest_version::*;
16+
pub use tool_config::*;

nextest-runner/src/config/tool_config.rs renamed to nextest-runner/src/config/core/tool_config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ impl FromStr for ToolConfigFile {
5757
mod tests {
5858
use super::*;
5959
use crate::config::{
60-
NextestConfig, NextestVersionConfig, NextestVersionReq, RetryPolicy, TestGroup,
61-
VersionOnlyConfig, test_helpers::*,
60+
core::{NextestConfig, NextestVersionConfig, NextestVersionReq, VersionOnlyConfig},
61+
elements::{RetryPolicy, TestGroup},
62+
utils::test_helpers::*,
6263
};
6364
use camino_tempfile::tempdir;
6465
use camino_tempfile_ext::prelude::*;

nextest-runner/src/config/archive.rs renamed to nextest-runner/src/config/elements/archive.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Copyright (c) The nextest Contributors
22
// SPDX-License-Identifier: MIT OR Apache-2.0
33

4-
use super::TrackDefault;
5-
use crate::config::helpers::deserialize_relative_path;
4+
use crate::config::utils::{TrackDefault, deserialize_relative_path};
65
use camino::{Utf8Component, Utf8Path, Utf8PathBuf};
76
use serde::{Deserialize, de::Unexpected};
87
use std::fmt;
@@ -238,10 +237,7 @@ impl<'de> Deserialize<'de> for RecursionDepth {
238237
mod tests {
239238
use super::*;
240239
use crate::{
241-
config::{
242-
NextestConfig,
243-
test_helpers::{build_platforms, temp_workspace},
244-
},
240+
config::{core::NextestConfig, utils::test_helpers::*},
245241
errors::ConfigParseErrorKind,
246242
};
247243
use camino::Utf8Path;

nextest-runner/src/config/global_timeout.rs renamed to nextest-runner/src/config/elements/global_timeout.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ impl<'de> Deserialize<'de> for GlobalTimeout {
2424
#[cfg(test)]
2525
mod tests {
2626
use super::*;
27-
use crate::config::{
28-
NextestConfig,
29-
test_helpers::{build_platforms, temp_workspace},
30-
};
27+
use crate::config::{core::NextestConfig, utils::test_helpers::*};
3128
use camino_tempfile::tempdir;
3229
use indoc::indoc;
3330
use nextest_filtering::ParseContext;

nextest-runner/src/config/junit.rs renamed to nextest-runner/src/config/elements/junit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde::Deserialize;
66

77
/// Global JUnit configuration stored within a profile.
88
///
9-
/// Returned by an [`EvaluatableProfile`](crate::config::EvaluatableProfile).
9+
/// Returned by an [`EvaluatableProfile`](crate::config::core::EvaluatableProfile).
1010
#[derive(Clone, Debug)]
1111
pub struct JunitConfig<'cfg> {
1212
path: Utf8PathBuf,
@@ -16,7 +16,7 @@ pub struct JunitConfig<'cfg> {
1616
}
1717

1818
impl<'cfg> JunitConfig<'cfg> {
19-
pub(super) fn new(
19+
pub(in crate::config) fn new(
2020
store_dir: &Utf8Path,
2121
custom_data: Option<&'cfg JunitImpl>,
2222
default_data: &'cfg DefaultJunitImpl,
@@ -68,7 +68,7 @@ impl<'cfg> JunitConfig<'cfg> {
6868
}
6969

7070
#[derive(Clone, Debug)]
71-
pub(super) struct DefaultJunitImpl {
71+
pub(in crate::config) struct DefaultJunitImpl {
7272
path: Option<Utf8PathBuf>,
7373
report_name: String,
7474
store_success_output: bool,
@@ -95,7 +95,7 @@ impl DefaultJunitImpl {
9595

9696
#[derive(Clone, Debug, Default, Deserialize)]
9797
#[serde(rename_all = "kebab-case")]
98-
pub(super) struct JunitImpl {
98+
pub(in crate::config) struct JunitImpl {
9999
#[serde(default)]
100100
path: Option<Utf8PathBuf>,
101101
#[serde(default)]

nextest-runner/src/config/leak_timeout.rs renamed to nextest-runner/src/config/elements/leak_timeout.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub enum LeakTimeoutResult {
4141
Pass,
4242
}
4343

44-
pub(super) fn deserialize_leak_timeout<'de, D>(
44+
pub(in crate::config) fn deserialize_leak_timeout<'de, D>(
4545
deserializer: D,
4646
) -> Result<Option<LeakTimeout>, D::Error>
4747
where
@@ -84,10 +84,7 @@ where
8484
#[cfg(test)]
8585
mod tests {
8686
use super::*;
87-
use crate::config::{
88-
NextestConfig,
89-
test_helpers::{build_platforms, temp_workspace},
90-
};
87+
use crate::config::{core::NextestConfig, utils::test_helpers::*};
9188
use camino_tempfile::tempdir;
9289
use indoc::indoc;
9390
use nextest_filtering::ParseContext;

0 commit comments

Comments
 (0)