Skip to content

Commit

Permalink
Merge e89deae into b51bff1
Browse files Browse the repository at this point in the history
  • Loading branch information
baoyachi committed Jun 20, 2022
2 parents b51bff1 + e89deae commit 9163c89
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Check fix
run: cargo fix && cargo fix
- name: Check with clippy
run: cargo clippy --all -- -D warnings
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Build Release
run: cargo build --release
- name: Run tests
Expand Down
7 changes: 4 additions & 3 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ impl SystemEnv {
if let Ok(out) = Command::new("cargo").arg("tree").output() {
let input = String::from_utf8(out.stdout)?;
if let Some(index) = input.find('\n') {
let lines = filter_cargo_tree(input[index..].split('\n').collect());
let lines =
filter_cargo_tree(input.get(index..).unwrap_or_default().split('\n').collect());
update_val(CARGO_TREE, lines);
}
}
Expand Down Expand Up @@ -168,7 +169,7 @@ mod dep_source_replace {
} else if let Some(index) = input.find(" (ssh") {
(DEP_REPLACE_GIT, index)
} else if let (Some(start), Some(end)) = (input.find(" ("), input.find(')')) {
let path = input[start + 2..end].trim();
let path = input.get(start + 2..end).unwrap_or_default().trim();
if path_exists(path) {
(DEP_REPLACE_PATH, start)
} else {
Expand All @@ -177,7 +178,7 @@ mod dep_source_replace {
} else {
(DEP_REPLACE_NONE, input.len())
};
format!("{}{}", &input[..index], val)
format!("{}{}", &input.get(..index).unwrap_or_default(), val)
}

pub fn filter_cargo_tree(lines: Vec<&str>) -> String {
Expand Down
16 changes: 12 additions & 4 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Git {
let mut short_commit = commit.as_str();

if commit.len() > 8 {
short_commit = &short_commit[0..8];
short_commit = short_commit.get(0..8).unwrap();
}
self.update_str(SHORT_COMMIT, short_commit.to_string());
}
Expand Down Expand Up @@ -184,9 +184,17 @@ impl Git {
let ref_tag_prefix: &str = "refs/tags/";

if v.starts_with(ref_branch_prefix) {
branch = Some(v[ref_branch_prefix.len()..].to_string())
branch = Some(
v.get(ref_branch_prefix.len()..)
.unwrap_or_default()
.to_string(),
)
} else if v.starts_with(ref_tag_prefix) {
tag = Some(v[ref_tag_prefix.len()..].to_string())
tag = Some(
v.get(ref_tag_prefix.len()..)
.unwrap_or_default()
.to_string(),
)
}
}
}
Expand Down Expand Up @@ -458,7 +466,7 @@ mod tests {
//assert github tag always exist value
if let Some(github_ref) = env_map.get("GITHUB_REF") {
if github_ref.starts_with("refs/tags/") && k.eq(TAG) {
assert!(!v.v.is_empty());
assert!(!v.v.is_empty(), "not empty");
} else if github_ref.starts_with("refs/heads/") && k.eq(BRANCH) {
assert!(!v.v.is_empty());
}
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,8 @@ mod tests {
fn test_build() -> SdResult<()> {
Shadow::build_inner("./".into(), "./".into())?;
let shadow = fs::read_to_string("./shadow.rs")?;
assert!(shadow.len() > 0);
let lines: Vec<_> = shadow.lines().map(|_| true).collect();
assert!(lines.len() > 0);
assert!(!shadow.is_empty());
assert!(shadow.lines().count() > 0);
println!("{}", shadow);
Ok(())
}
Expand Down

0 comments on commit 9163c89

Please sign in to comment.