Skip to content

Commit bda3509

Browse files
committed
Increase coverage
1 parent 04d6ab9 commit bda3509

File tree

4 files changed

+44
-53
lines changed

4 files changed

+44
-53
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ jobs:
7878
parallel: true
7979
flag-name: ${{ matrix.os }}-unit
8080

81-
- uses: actions/upload-artifact@v4
82-
with:
83-
path: ./target/release/pkgx
84-
8581
coverage-integration:
8682
needs: fmt
8783
strategy:
@@ -95,6 +91,10 @@ jobs:
9591

9692
- uses: dtolnay/rust-toolchain@stable
9793

94+
- uses: taiki-e/install-action@v2
95+
with:
96+
tool: rustfilt
97+
9898
- name: build
9999
run: |
100100
RUSTFLAGS="-C instrument-coverage" cargo build
@@ -158,23 +158,13 @@ jobs:
158158
pkgx -Q hyperfine
159159
! test -d ~/.pkgx/crates.io/hyperfine
160160
! pkgx -Q flubber-flubber
161+
! pkgx -Qqq flubber-flubber
162+
pkgx -Q
161163
162164
- run: if [ $(find ~/.pkgx -name .tmp\* -type d | wc -l) -gt 0 ]; then
163165
exit 1;
164166
fi
165167

166-
- name: generate coverage
167-
run: |
168-
cargo install rustfilt
169-
pkgx +llvm.org -- llvm-profdata merge -sparse default_*.profraw -o default.profdata
170-
pkgx +llvm.org -- llvm-cov export \
171-
./target/debug/pkgx \
172-
--format=lcov \
173-
--ignore-filename-regex="$HOME/.cargo" \
174-
--instr-profile=default.profdata \
175-
-Xdemangler=rustfilt \
176-
> lcov.info
177-
178168
- name: --shebang test 1
179169
run: |
180170
echo "#!/usr/bin/env -S pkgx --shebang echo" > ./stub.sh
@@ -189,6 +179,26 @@ jobs:
189179
pkgx semverator eq $(pkgx krampus=0.2.0 --version) 0.2.0
190180
pkgx semverator gt $(pkgx krampus@latest --version) 0.2.0
191181
182+
- name: PKGX_PANTRY_DIR
183+
run: |
184+
git clone https://github.com/pkgxdev/pantry
185+
pkgx hyperfine --version
186+
PKGX_PANTRY_DIR=pantry pkgx hyperfine --version
187+
env:
188+
PKGX_PANTRY_DIR: ${{ github.workspace }}/pantry
189+
PKGX_DIR: ${{ github.workspace }}/pkgx
190+
191+
- name: generate coverage
192+
run: |
193+
pkgx +llvm.org -- llvm-profdata merge -sparse default_*.profraw -o default.profdata
194+
pkgx +llvm.org -- llvm-cov export \
195+
./target/debug/pkgx \
196+
--format=lcov \
197+
--ignore-filename-regex="$HOME/.cargo" \
198+
--instr-profile=default.profdata \
199+
-Xdemangler=rustfilt \
200+
> lcov.info
201+
192202
- uses: coverallsapp/github-action@v2
193203
with:
194204
path-to-lcov: lcov.info

crates/cli/src/args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn parse() -> Args {
5252
"--json" => {
5353
if !silent {
5454
eprintln!(
55-
"{} use --json={}",
55+
"{} use --json=v{}",
5656
style("warning: --json is not stable").yellow(),
5757
json_latest_v
5858
);
@@ -75,7 +75,7 @@ pub fn parse() -> Args {
7575
style("│").red()
7676
);
7777
eprintln!(
78-
"{} you need to migrate to the new, isolated `dev` command",
78+
"{} you need to migrate to the new, independent `dev` command",
7979
style("│").red()
8080
);
8181
eprintln!("{} run the following:", style("│").red());

crates/cli/src/resolve.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use libpkgx::{
88
};
99
use rusqlite::Connection;
1010

11-
use crate::{spinner::Spinner, which};
11+
use crate::{
12+
spinner::Spinner,
13+
which::{which, WhichError},
14+
};
1215

1316
pub async fn resolve(
1417
args: &mut [String],
@@ -32,7 +35,7 @@ pub async fn resolve(
3235
.join(pkgspec.project())
3336
.is_dir()
3437
{
35-
let project = which::which(&pkgspec.project(), conn, &pkgs).await?;
38+
let project = which(&pkgspec.project(), conn, &pkgs).await?;
3639
pkgspec.set_project(project);
3740
}
3841

@@ -45,15 +48,15 @@ pub async fn resolve(
4548

4649
args[0] = cmd.clone(); // invoke eg. `node` rather than eg. `node@20`
4750

48-
let project = match which::which(&cmd, conn, &pkgs).await {
49-
Err(which::WhichError::CmdNotFound(cmd)) => {
51+
let project = match which(&cmd, conn, &pkgs).await {
52+
Err(WhichError::CmdNotFound(cmd)) => {
5053
if !did_sync {
5154
spinner.set_message(&format!("{} not found, syncing…", cmd));
5255
sync::update(config, conn).await?; // cmd not found ∴ sync in case it is new
5356
spinner.set_message("resolving pkg graph…");
54-
which::which(&cmd, conn, &pkgs).await
57+
which(&cmd, conn, &pkgs).await
5558
} else {
56-
Err(which::WhichError::CmdNotFound(cmd))
59+
Err(WhichError::CmdNotFound(cmd))
5760
}
5861
}
5962
Err(err) => Err(err),

crates/lib/src/inventory.rs

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,6 @@ use libsemverator::semver::Semver as Version;
55
use reqwest::Url;
66
use std::error::Error;
77

8-
// Custom error for download issues
9-
#[derive(Debug)]
10-
pub struct DownloadError {
11-
pub status: u16,
12-
pub src: String,
13-
}
14-
15-
impl std::fmt::Display for DownloadError {
16-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17-
write!(
18-
f,
19-
"Download error: status code {} from {}",
20-
self.status, self.src
21-
)
22-
}
23-
}
24-
25-
impl Error for DownloadError {}
26-
278
// Select function to pick a version
289
pub async fn select(rq: &PackageReq, config: &Config) -> Result<Option<Version>, Box<dyn Error>> {
2910
let versions = ls(&rq.project, config).await?;
@@ -45,14 +26,11 @@ pub async fn ls(project: &String, config: &Config) -> Result<Vec<Version>, Box<d
4526
base_url, project, platform, arch
4627
))?;
4728

48-
let rsp = build_client()?.get(url.clone()).send().await?;
49-
50-
if !rsp.status().is_success() {
51-
return Err(Box::new(DownloadError {
52-
status: rsp.status().as_u16(),
53-
src: url.to_string(),
54-
}));
55-
}
29+
let rsp = build_client()?
30+
.get(url.clone())
31+
.send()
32+
.await?
33+
.error_for_status()?;
5634

5735
let releases = rsp.text().await?;
5836
let mut versions: Vec<Version> = releases
@@ -63,8 +41,8 @@ pub async fn ls(project: &String, config: &Config) -> Result<Vec<Version>, Box<d
6341

6442
if versions.is_empty() {
6543
return Err(Box::new(std::io::Error::new(
66-
std::io::ErrorKind::Other,
67-
format!("No versions for {}", project),
44+
std::io::ErrorKind::NotFound,
45+
format!("No inventory for {}", project),
6846
)));
6947
}
7048

0 commit comments

Comments
 (0)