|
2 | 2 |
|
3 | 3 | use crate::{check::*, error::*};
|
4 | 4 | use std::{
|
5 |
| - fmt, fs, |
| 5 | + fs, |
6 | 6 | os::unix::io::*,
|
7 | 7 | path::*,
|
8 | 8 | process::{Command, Stdio},
|
@@ -118,7 +118,7 @@ pub enum Target {
|
118 | 118 | }
|
119 | 119 |
|
120 | 120 | impl FromStr for Target {
|
121 |
| - type Err = ParseTargetError; |
| 121 | + type Err = Error; |
122 | 122 |
|
123 | 123 | fn from_str(s: &str) -> Result<Self, Self::Err> {
|
124 | 124 | let target = match s.to_ascii_lowercase().as_str() {
|
@@ -195,21 +195,16 @@ impl FromStr for Target {
|
195 | 195 | "zarch_generic" => Self::ZARCH_GENERIC,
|
196 | 196 | "z13" => Self::Z13,
|
197 | 197 | "z14" => Self::Z14,
|
198 |
| - _ => return Err(ParseTargetError::default()), |
| 198 | + _ => { |
| 199 | + return Err(Error::UnsupportedTarget { |
| 200 | + target: s.to_string(), |
| 201 | + }) |
| 202 | + } |
199 | 203 | };
|
200 | 204 | Ok(target)
|
201 | 205 | }
|
202 | 206 | }
|
203 | 207 |
|
204 |
| -#[derive(Debug, Clone, PartialEq, Eq, Default)] |
205 |
| -pub struct ParseTargetError; |
206 |
| - |
207 |
| -impl fmt::Display for ParseTargetError { |
208 |
| - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
209 |
| - "provided string was not a valid target".fmt(f) |
210 |
| - } |
211 |
| -} |
212 |
| - |
213 | 208 | /// make option generator
|
214 | 209 | #[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
215 | 210 | pub struct Configure {
|
@@ -408,6 +403,15 @@ impl Configure {
|
408 | 403 | mod tests {
|
409 | 404 | use super::*;
|
410 | 405 |
|
| 406 | + #[test] |
| 407 | + fn target_from_str() { |
| 408 | + assert_eq!(Target::from_str("p2").unwrap(), Target::P2); |
| 409 | + assert!(matches!( |
| 410 | + Target::from_str("p3").unwrap_err(), |
| 411 | + crate::error::Error::UnsupportedTarget { .. } |
| 412 | + )); |
| 413 | + } |
| 414 | + |
411 | 415 | #[ignore]
|
412 | 416 | #[test]
|
413 | 417 | fn build_default() {
|
|
0 commit comments