-
Notifications
You must be signed in to change notification settings - Fork 240
Add --partition flag
#3852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
franciszekjob
wants to merge
9
commits into
master
Choose a base branch
from
3548-partition-flag
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+112
−3
Open
Add --partition flag
#3852
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
de6ad3a
Add `--partition` flag
franciszekjob 663dcdf
Add missing conflict
franciszekjob 70e6801
Refactor tests
franciszekjob e4960e8
Update help message
franciszekjob d026e10
Add comment
franciszekjob 4ef5c98
Merge branch 'master' into 3548-partition-flag
franciszekjob 44d059c
Apply code review suggestion
franciszekjob 1937f60
Merge branch '3548-partition-flag' of https://github.com/foundry-rs/s…
franciszekjob ace3997
Merge branch 'master' into 3548-partition-flag
franciszekjob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| use serde::Serialize; | ||
| use std::{collections::HashMap, str::FromStr}; | ||
|
|
||
| #[derive(Debug, Clone, Copy, Serialize)] | ||
| #[non_exhaustive] | ||
| pub struct Partition { | ||
| pub index: usize, | ||
| pub total: usize, | ||
| } | ||
|
|
||
| impl FromStr for Partition { | ||
| type Err = String; | ||
|
|
||
| fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { | ||
| let parts: Vec<&str> = s.split('/').collect(); | ||
|
|
||
| if parts.len() != 2 { | ||
| return Err("Partition must be in the format <INDEX>/<TOTAL>".to_string()); | ||
| } | ||
|
|
||
| let index = parts[0] | ||
| .parse::<usize>() | ||
| .map_err(|_| "INDEX must be a positive integer".to_string())?; | ||
| let total = parts[1] | ||
| .parse::<usize>() | ||
| .map_err(|_| "TOTAL must be a positive integer".to_string())?; | ||
|
|
||
| if index == 0 || total == 0 || index > total { | ||
| return Err("Invalid partition values: ensure 1 <= INDEX <= TOTAL".to_string()); | ||
| } | ||
|
|
||
| Ok(Partition { index, total }) | ||
| } | ||
| } | ||
|
|
||
| /// A mapping between test full paths and their assigned partition indices. | ||
| #[derive(Serialize)] | ||
| pub struct TestPartitionMap(HashMap<String, usize>); | ||
|
|
||
| #[derive(Serialize)] | ||
| #[non_exhaustive] | ||
| pub struct PartitionConfig { | ||
| pub partition: Partition, | ||
| pub test_partition_map: TestPartitionMap, | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use test_case::test_case; | ||
|
|
||
| #[test] | ||
| fn test_happy_case() { | ||
| let partition = "2/5".parse::<Partition>().unwrap(); | ||
| assert_eq!(partition.index, 2); | ||
| assert_eq!(partition.total, 5); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_invalid_format() { | ||
| let err = "2-5".parse::<Partition>().unwrap_err(); | ||
| assert_eq!(err, "Partition must be in the format <INDEX>/<TOTAL>"); | ||
| } | ||
|
|
||
| // #[test] | ||
| #[test_case("-1/5", "INDEX")] | ||
| #[test_case("2/-5", "TOTAL")] | ||
| #[test_case("a/5", "INDEX")] | ||
| #[test_case("2/b", "TOTAL")] | ||
| fn test_invalid_integer(partition: &str, invalid_part: &str) { | ||
| let err = partition.parse::<Partition>().unwrap_err(); | ||
| assert_eq!(err, format!("{invalid_part} must be a positive integer")); | ||
| } | ||
|
|
||
| #[test_case("0/5")] | ||
| #[test_case("6/5")] | ||
| #[test_case("2/0")] | ||
| fn test_out_of_bounds(partition: &str) { | ||
| let err = partition.parse::<Partition>().unwrap_err(); | ||
| assert_eq!(err, "Invalid partition values: ensure 1 <= INDEX <= TOTAL"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| use crate::e2e::common::runner::{setup_package, test_runner}; | ||
| use indoc::indoc; | ||
| use shared::test_utils::output_assert::assert_stderr_contains; | ||
|
|
||
| #[test] | ||
| fn test_does_not_work_with_exact_flag() { | ||
| let temp = setup_package("simple_package"); | ||
| let output = test_runner(&temp) | ||
| .args(["--partition", "3/3", "--workspace", "--exact"]) | ||
| .assert() | ||
| .code(2); | ||
|
|
||
| assert_stderr_contains( | ||
| output, | ||
| indoc! {r" | ||
| error: the argument '--partition <PARTITION>' cannot be used with '--exact' | ||
| "}, | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover?