You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shell脚本参数在Bats测试中无法传递的问题排查

Bats测试脚本参数传递问题

目录结构

geoloc-util.sh
tests
  |- test_geoloc_util.bats

正常执行情况

在项目根目录下执行以下命令,输出均符合预期:

./geoloc-util.sh "Madison, WI" "94552"
./geoloc-util.sh -l "Madison, WI" "94552"
./geoloc-util.sh --location "Madison, WI" "94552"

测试中的异常

当前Bats测试代码如下:

@test "Valid city and state" {
  ../geoloc-util.sh --locations "Madison, WI"
  [ "$status" -eq 0 ]
  [[ "$output" == *"Location: Madison, WI, US"* ]]
  [[ "$output" == *"Latitude:"* ]]
  [[ "$output" == *"Longitude:"* ]]
}

执行测试内的../geoloc-util.sh --locations "Madison, WI"时,参数未正确传递。在geoloc-util.sh顶部添加echo "$@"调试后,输出仅包含脚本文件路径,看不到传入的--locations "Madison, WI"参数。已尝试使用run、run bash命令,查阅相关文档仍未解决,期望Bats测试中的调用效果与CLI直接执行完全一致。

内容的提问来源于stack exchange,提问作者B12

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 05:42:04