Loading test/build.bats 0 → 100644 +81 −0 Original line number Diff line number Diff line #!/usr/bin/env bats load test_helper tarball() { local name="$1" local path="$TMP/$name" local configure="$path/configure" mkdir -p "$path" cat > "$configure" <<OUT #!$BASH echo "$name: \$@" > build.log OUT chmod +x "$configure" tar czf "${path}.tgz" -C "$TMP" "$name" echo "${path}.tgz" } stub_download() { stub curl "-C - -o * -*S* $1 : cp '$(tarball "$2")' \$4" } @test "yaml is installed for ruby" { mkdir -p "$INSTALL_ROOT/bin" stub md5 false stub brew false stub_download "http://pyyaml.org/*" "yaml-0.1.4" stub_download "http://ruby-lang.org/*" "ruby-2.0.0" stub make \ ' : echo make "$@" >> build.log' \ "install : cp build.log '$INSTALL_ROOT/yaml.log'" \ ' : echo make "$@" >> build.log' \ "install : cp build.log '$INSTALL_ROOT/ruby.log'" install_fixture definitions/needs-yaml assert_success unstub curl unstub make run cat "$INSTALL_ROOT/yaml.log" assert_output <<OUT yaml-0.1.4: --prefix=$INSTALL_ROOT make -j 2 OUT run cat "$INSTALL_ROOT/ruby.log" assert_output <<OUT ruby-2.0.0: --prefix=$INSTALL_ROOT make -j 2 OUT } @test "yaml is linked from Homebrew" { brew_libdir="$TMP/homebrew-yaml" mkdir -p "$INSTALL_ROOT/bin" mkdir -p "$brew_libdir" stub md5 false stub brew "--prefix libyaml : echo '$brew_libdir'" stub_download "http://ruby-lang.org/*" "ruby-2.0.0" stub make \ ' : echo make "$@" >> build.log' \ "install : cp build.log '$INSTALL_ROOT/ruby.log'" install_fixture definitions/needs-yaml assert_success unstub brew unstub curl unstub make run cat "$INSTALL_ROOT/ruby.log" assert_output <<OUT ruby-2.0.0: --prefix=$INSTALL_ROOT --with-libyaml-dir=$brew_libdir make -j 2 OUT } test/fixtures/definitions/needs-yaml 0 → 100644 +2 −0 Original line number Diff line number Diff line install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz" --if needs_yaml install_package "ruby-2.0.0" "http://ruby-lang.org/ruby/2.0/ruby-2.0.0.tar.gz" test/test_helper.bash +49 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ stub() { mkdir -p "${TMP}/bin" ln -shf "${BATS_TEST_DIRNAME}/stubs/stub" "${TMP}/bin/${program}" rm -f "${TMP}/${program}-stub-plan" "${TMP}/${program}-stub-run" touch "${TMP}/${program}-stub-plan" for arg in "$@"; do printf "%s\n" "$arg" >> "${TMP}/${program}-stub-plan"; done } Loading @@ -37,6 +36,7 @@ unstub() { "$path" rm -f "$path" rm -f "${TMP}/${program}-stub-plan" "${TMP}/${program}-stub-run" } install_fixture() { Loading @@ -46,3 +46,51 @@ install_fixture() { run ruby-build "$FIXTURE_ROOT/$name" "$destination" } assert() { if ! "$@"; then flunk "failed: $@" fi } flunk() { { if [ "$#" -eq 0 ]; then cat - else echo "$@" fi } | sed "s:${TMP}:\${TMP}:g" >&2 return 1 } assert_success() { if [ "$status" -ne 0 ]; then { echo "command failed with exit status $status" echo "output: $output" } | flunk elif [ "$#" -gt 0 ]; then assert_output "$1" fi } assert_failure() { if [ "$status" -eq 0 ]; then flunk "expected failed exit status" elif [ "$#" -gt 0 ]; then assert_output "$1" fi } assert_equal() { if [ "$1" != "$2" ]; then { echo "expected: $1" echo "actual: $2" } | flunk fi } assert_output() { local expected if [ $# -eq 0 ]; then expected="$(cat -)" else expected="$1" fi assert_equal "$expected" "$output" } Loading
test/build.bats 0 → 100644 +81 −0 Original line number Diff line number Diff line #!/usr/bin/env bats load test_helper tarball() { local name="$1" local path="$TMP/$name" local configure="$path/configure" mkdir -p "$path" cat > "$configure" <<OUT #!$BASH echo "$name: \$@" > build.log OUT chmod +x "$configure" tar czf "${path}.tgz" -C "$TMP" "$name" echo "${path}.tgz" } stub_download() { stub curl "-C - -o * -*S* $1 : cp '$(tarball "$2")' \$4" } @test "yaml is installed for ruby" { mkdir -p "$INSTALL_ROOT/bin" stub md5 false stub brew false stub_download "http://pyyaml.org/*" "yaml-0.1.4" stub_download "http://ruby-lang.org/*" "ruby-2.0.0" stub make \ ' : echo make "$@" >> build.log' \ "install : cp build.log '$INSTALL_ROOT/yaml.log'" \ ' : echo make "$@" >> build.log' \ "install : cp build.log '$INSTALL_ROOT/ruby.log'" install_fixture definitions/needs-yaml assert_success unstub curl unstub make run cat "$INSTALL_ROOT/yaml.log" assert_output <<OUT yaml-0.1.4: --prefix=$INSTALL_ROOT make -j 2 OUT run cat "$INSTALL_ROOT/ruby.log" assert_output <<OUT ruby-2.0.0: --prefix=$INSTALL_ROOT make -j 2 OUT } @test "yaml is linked from Homebrew" { brew_libdir="$TMP/homebrew-yaml" mkdir -p "$INSTALL_ROOT/bin" mkdir -p "$brew_libdir" stub md5 false stub brew "--prefix libyaml : echo '$brew_libdir'" stub_download "http://ruby-lang.org/*" "ruby-2.0.0" stub make \ ' : echo make "$@" >> build.log' \ "install : cp build.log '$INSTALL_ROOT/ruby.log'" install_fixture definitions/needs-yaml assert_success unstub brew unstub curl unstub make run cat "$INSTALL_ROOT/ruby.log" assert_output <<OUT ruby-2.0.0: --prefix=$INSTALL_ROOT --with-libyaml-dir=$brew_libdir make -j 2 OUT }
test/fixtures/definitions/needs-yaml 0 → 100644 +2 −0 Original line number Diff line number Diff line install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz" --if needs_yaml install_package "ruby-2.0.0" "http://ruby-lang.org/ruby/2.0/ruby-2.0.0.tar.gz"
test/test_helper.bash +49 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ stub() { mkdir -p "${TMP}/bin" ln -shf "${BATS_TEST_DIRNAME}/stubs/stub" "${TMP}/bin/${program}" rm -f "${TMP}/${program}-stub-plan" "${TMP}/${program}-stub-run" touch "${TMP}/${program}-stub-plan" for arg in "$@"; do printf "%s\n" "$arg" >> "${TMP}/${program}-stub-plan"; done } Loading @@ -37,6 +36,7 @@ unstub() { "$path" rm -f "$path" rm -f "${TMP}/${program}-stub-plan" "${TMP}/${program}-stub-run" } install_fixture() { Loading @@ -46,3 +46,51 @@ install_fixture() { run ruby-build "$FIXTURE_ROOT/$name" "$destination" } assert() { if ! "$@"; then flunk "failed: $@" fi } flunk() { { if [ "$#" -eq 0 ]; then cat - else echo "$@" fi } | sed "s:${TMP}:\${TMP}:g" >&2 return 1 } assert_success() { if [ "$status" -ne 0 ]; then { echo "command failed with exit status $status" echo "output: $output" } | flunk elif [ "$#" -gt 0 ]; then assert_output "$1" fi } assert_failure() { if [ "$status" -eq 0 ]; then flunk "expected failed exit status" elif [ "$#" -gt 0 ]; then assert_output "$1" fi } assert_equal() { if [ "$1" != "$2" ]; then { echo "expected: $1" echo "actual: $2" } | flunk fi } assert_output() { local expected if [ $# -eq 0 ]; then expected="$(cat -)" else expected="$1" fi assert_equal "$expected" "$output" }