-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(macros): add
SetOptions { profile }
command (#1404)
- Loading branch information
Showing
10 changed files
with
121 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
60 changes: 60 additions & 0 deletions
60
packages/fuels-macros/src/setup_program_test/parsing/commands/set_options.rs
This file contains 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,60 @@ | ||
use std::{convert::TryFrom, fmt, str::FromStr}; | ||
|
||
use syn::Error; | ||
|
||
use crate::parse_utils::{Command, UniqueNameValues}; | ||
|
||
#[derive(Debug, Clone, Default, PartialEq, Eq)] | ||
pub enum BuildProfile { | ||
Debug, | ||
#[default] | ||
Release, | ||
} | ||
|
||
impl FromStr for BuildProfile { | ||
type Err = &'static str; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s { | ||
"debug" => Ok(Self::Debug), | ||
"release" => Ok(Self::Release), | ||
_ => Err(r#"invalid build profile option: must be "debug" or "release""#), | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for BuildProfile { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!( | ||
f, | ||
"{}", | ||
match self { | ||
BuildProfile::Debug => "debug", | ||
BuildProfile::Release => "release", | ||
} | ||
) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct SetOptionsCommand { | ||
pub profile: BuildProfile, | ||
} | ||
|
||
impl TryFrom<Command> for SetOptionsCommand { | ||
type Error = Error; | ||
|
||
fn try_from(command: Command) -> Result<Self, Self::Error> { | ||
let name_values = UniqueNameValues::new(command.contents)?; | ||
name_values.validate_has_no_other_names(&["profile"])?; | ||
|
||
let profile = name_values.get_as_lit_str("profile")?; | ||
let profile = profile | ||
.value() | ||
.as_str() | ||
.parse() | ||
.map_err(|msg| Error::new(profile.span(), msg))?; | ||
|
||
Ok(Self { profile }) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr
This file contains 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
5 changes: 5 additions & 0 deletions
5
packages/fuels-macros/tests/ui/setup_program_test/unknown_options_key.rs
This file contains 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,5 @@ | ||
use fuels_macros::setup_program_test; | ||
|
||
setup_program_test!(Options(unknown = "debug")); | ||
|
||
fn main() {} |
5 changes: 5 additions & 0 deletions
5
packages/fuels-macros/tests/ui/setup_program_test/unknown_options_key.stderr
This file contains 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,5 @@ | ||
error: attribute 'unknown' not recognized. Expected one of: 'profile' | ||
--> tests/ui/setup_program_test/unknown_options_key.rs:3:29 | ||
| | ||
3 | setup_program_test!(Options(unknown = "debug")); | ||
| ^^^^^^^ |
5 changes: 5 additions & 0 deletions
5
packages/fuels-macros/tests/ui/setup_program_test/unknown_options_value.rs
This file contains 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,5 @@ | ||
use fuels_macros::setup_program_test; | ||
|
||
setup_program_test!(Options(profile = "not_a_profile")); | ||
|
||
fn main() {} |
5 changes: 5 additions & 0 deletions
5
packages/fuels-macros/tests/ui/setup_program_test/unknown_options_value.stderr
This file contains 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,5 @@ | ||
error: invalid build profile option: must be "debug" or "release" | ||
--> tests/ui/setup_program_test/unknown_options_value.rs:3:39 | ||
| | ||
3 | setup_program_test!(Options(profile = "not_a_profile")); | ||
| ^^^^^^^^^^^^^^^ |