From 3445ef5749b78b60c578638de41ca041cc2fbd51 Mon Sep 17 00:00:00 2001 From: sigoden Date: Wed, 29 May 2024 09:08:17 +0800 Subject: [PATCH] refactor: optimize build script (#333) --- .github/workflows/ci.yaml | 7 +++++++ src/build.rs | 4 +++- tests/cli.rs | 32 ++++++++++++++++---------------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6399a10..ddfe663 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -36,6 +36,13 @@ jobs: - uses: Swatinem/rust-cache@v2 + - name: Install Bash 5 on macOS + if: runner.os == 'macOS' + run: | + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" + brew install bash + bash --version + - name: Test run: cargo test --all diff --git a/src/build.rs b/src/build.rs index 95f8e2f..464a1d8 100644 --- a/src/build.rs +++ b/src/build.rs @@ -140,7 +140,9 @@ _argc_require_params() { r#" _argc_validate_choices() { local render_name="$1" raw_choices="$2" choices item choice concated_choices="" - IFS=$'\n' read -r -d '' -a choices <<<"$raw_choices" || true + while IFS= read -r line; do + choices+=("$line") + done <<<"$raw_choices" for choice in "${choices[@]}"; do if [[ -z "$concated_choices" ]]; then concated_choices="$choice" diff --git a/tests/cli.rs b/tests/cli.rs index 6eb6f5f..ea6bf3f 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -110,22 +110,22 @@ fn run_build() { .assert() .success(); - // Command::cargo_bin("argc") - // .unwrap() - // .arg("--argc-run") - // .arg(&outpath) - // .args([ - // "--fa", - // "--oa", - // "oa1", - // "--of=of1,of2", - // "--oca=a", - // "--ofa", - // "abc", - // ]) - // .assert() - // .stdout(predicates::str::contains("argc__fn=main")) - // .success(); + Command::cargo_bin("argc") + .unwrap() + .arg("--argc-run") + .arg(&outpath) + .args([ + "--fa", + "--oa", + "oa1", + "--of=of1,of2", + "--oca=a", + "--ofa", + "abc", + ]) + .assert() + .stdout(predicates::str::contains("argc__fn=main")) + .success(); } #[test]