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
相关产品推荐
相关产品推荐

