首页 > 解决方案 > 锻炼 Bash Track

问题描述

我正在 exercism.io 上尝试 bash 课程 https://exercism.io/my/solutions/8d68ead0c1ad4caabf25410806ade766

我已经安装了练习文件,安装了 bats,当我运行测试时:bats hello_world_test.sh

它输出和错误:

$ bats hello_world_test.sh
 ✗ Say Hi!
   (in test file hello_world_test.sh, line 6)
     `[ "$status" -eq 0 ]' failed

bats hello_world_test.sh 的代码是:

#!/usr/bin/env bash

@test "Say Hi!" {
  run bash hello_world.sh

  [ "$status" -eq 0 ]
  [ "$output" = "Hello, World!" ]
}

标签: bashbats-core

解决方案


这一行告诉我们我们需要知道的一切:

run bash hello_world.sh

...您的hello_world_test.sh脚本正在尝试执行名为hello_world.sh. 该[ "$status" -eq 0 ]行失败是因为 bash 返回了错误代码(很可能是因为hello_world.sh脚本不存在)。您将需要创建此文件。

但是,仅仅创建脚本不足以使测试用例通过;它还期望输出“Hello, World!” 从这个脚本。我不会告诉你如何做到这一点,因为那样会破坏目标,但我会向你推荐一个应该让你启动并运行的HOW TO 。我鼓励您阅读整个指南,其中有很多很好的信息可供刚入门的人使用。这可能需要你尝试几次,但你会明白的:-)


推荐阅读