Skip to content

Commit e05c0a4

Browse files
committed
Changed test/setup to generate a fake stub bin/ruby based on test/helpers/ruby.sh.
1 parent 685a774 commit e05c0a4

File tree

4 files changed

+44
-164
lines changed

4 files changed

+44
-164
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/pkg/*.tar.gz
33
/pkg/*.tar.bz2
44
/pkg/*.zip
5-
/test/fixtures/opt/rubies
6-
/test/fixtures/home/.zcompdump
5+
/test/fixtures/root/opt/rubies
6+
/test/fixtures/root/home/.zcompdump
77
/test/fixtures/ruby_versions/.ruby-version
88
/test/fixtures/ruby_versions/modified_version/.ruby-version

test/helpers/fixtures.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test_fixtures_dir="$PWD/test/fixtures"
2+
test_fixtures_root="$test_fixtures_dir/root"

test/helpers/ruby.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
. ./test/helpers/fixtures.sh
2+
13
if [[ -n "$TEST_RUBY_ROOT" ]]; then
24
test_ruby_root="${TEST_RUBY_ROOT}"
35

test/setup

Lines changed: 38 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -2,175 +2,51 @@
22

33
. ./test/helpers/ruby.sh
44

5-
function log() {
6-
if [[ -t 1 ]]; then
7-
printf "%b>>>%b %b%s%b\n" "\x1b[1m\x1b[32m" "\x1b[0m" \
8-
"\x1b[1m\x1b[37m" "$1" "\x1b[0m"
9-
else
10-
printf ">>> %s\n" "$1"
11-
fi
12-
}
5+
test_dir="${0%/*}"
6+
test_fixtures_dir="$test_dir/fixtures"
7+
test_fixtures_root="$test_fixtures_dir/root"
8+
test_rubies_dir="$test_fixtures_root/opt/rubies"
139

14-
function error() {
15-
if [[ -t 1 ]]; then
16-
printf "%b!!!%b %b%s%b\n" "\x1b[1m\x1b[31m" "\x1b[0m" \
17-
"\x1b[1m\x1b[37m" "$1" "\x1b[0m" >&2
18-
else
19-
printf "!!! %s\n" "$1" >&2
20-
fi
21-
}
10+
ruby_dir="$test_rubies_dir/$test_ruby_engine-$test_ruby_version"
2211

23-
function fail() {
24-
error "$1"
25-
exit -1
26-
}
12+
mkdir -p "$test_rubies_dir"
13+
mkdir -p "$ruby_dir/bin"
2714

28-
function download() {
29-
if command -v wget >/dev/null; then
30-
wget -q -c -O "$2" "$1"
31-
elif command -v curl >/dev/null; then
32-
curl -s -S -L -C - -o "$2" "$1"
33-
else
34-
error "Could not find wget or curl"
35-
return 1
36-
fi
37-
}
15+
cat > "$ruby_dir/bin/ruby" <<EOF
16+
#!/usr/bin/env bash
3817
39-
function detect_system() {
40-
# adapted from RVM: https://github.com/wayneeseguin/rvm/blob/master/scripts/functions/utility_system#L3
41-
system_type="unknown"
42-
system_name="unknown"
43-
system_version="unknown"
44-
system_arch="$(uname -m)"
45-
46-
case "$(uname)" in
47-
(Linux|GNU*)
48-
system_type="linux"
49-
50-
if [[ -f /etc/lsb-release ]] && [[ "$(< /etc/lsb-release)" == *"DISTRIB_ID=Ubuntu"* ]]; then
51-
system_name="ubuntu"
52-
system_version="$(awk -F'=' '$1=="DISTRIB_RELEASE"{print $2}' /etc/lsb-release)"
53-
system_arch="$(dpkg --print-architecture)"
54-
elif [[ -f /etc/lsb-release ]] && [[ "$(< /etc/lsb-release)" == *"DISTRIB_ID=LinuxMint"* ]]; then
55-
system_name="mint"
56-
system_version="$(awk -F'=' '$1=="DISTRIB_RELEASE"{print $2}' /etc/lsb-release)"
57-
system_arch="$( dpkg --print-architecture )"
58-
elif [[ -f /etc/lsb-release ]] && [[ "$(< /etc/lsb-release)" == *"DISTRIB_ID=ManjaroLinux"* ]]; then
59-
system_name="manjaro"
60-
system_version="$(awk -F'=' '$1=="DISTRIB_RELEASE"{print $2}' /etc/lsb-release)"
61-
elif [[ -f /etc/os-release ]] && [[ "$(< /etc/os-release)" == *"ID=opensuse"* ]]; then
62-
system_name="opensuse"
63-
system_version="$(awk -F'=' '$1=="VERSION_ID"{gsub(/"/,"");print $2}' /etc/os-release)" #'
64-
elif [[ -f /etc/SuSE-release ]]; then
65-
system_name="suse"
66-
system_version="$(
67-
awk -F'=' '{gsub(/ /,"")} $1~/VERSION/ {version=$2} $1~/PATCHLEVEL/ {patch=$2} END {print version"."patch}' < /etc/SuSE-release
68-
)"
69-
elif [[ -f /etc/debian_version ]]; then
70-
system_name="debian"
71-
system_version="$(awk -F. '{print $1"."$2}' /etc/debian_version)"
72-
system_arch="$( dpkg --print-architecture )"
73-
elif [[ -f /etc/os-release ]] && [[ "$(< /etc/os-release)" == *"ID=debian"* ]]; then
74-
system_name="debian"
75-
system_version="$(awk -F'=' '$1=="VERSION_ID"{gsub(/"/,"");print $2}' /etc/os-release | awk -F. '{print $1"."$2}')" #'
76-
system_arch="$( dpkg --print-architecture )"
77-
elif [[ -f /etc/fedora-release ]]; then
78-
system_name="fedora"
79-
system_version="$(grep -Eo '[[:digit:]]+' /etc/fedora-release)"
80-
elif [[ -f /etc/centos-release ]]; then
81-
system_name="centos"
82-
system_version="$(grep -Eo '[[:digit:]\.]+' /etc/centos-release | awk -F. '{print $1"."$2}')"
83-
elif [[ -f /etc/redhat-release ]]; then
84-
if [[ "$(< /etc/redhat-release)" == *"CentOS"* ]]; then
85-
system_name="centos"
86-
else
87-
system_name="redhat"
88-
fi
89-
90-
system_version="$(grep -Eo '[[:digit:]\.]+' /etc/redhat-release | awk -F. '{print $1"."$2}')"
91-
elif [[ -f /etc/system-release ]] && [[ "$(< /etc/system-release)" == *"Amazon Linux AMI"* ]]; then
92-
system_name="amazon"
93-
system_version="$(grep -Eo '[[:digit:]\.]+' /etc/system-release | awk -F. '{print $1"."$2}')"
94-
elif [[ -f /etc/gentoo-release ]]; then
95-
system_name="gentoo"
96-
system_version="base-$(< /etc/gentoo-release | awk 'NR==1 {print $NF}' | awk -F. '{print $1"."$2}')"
97-
elif [[ -f /etc/arch-release ]]; then
98-
system_name="arch"
99-
system_version="libc-$(ldd --version | awk 'NR==1 {print $NF}' | awk -F. '{print $1"."$2}')"
100-
else
101-
system_version="libc-$(ldd --version | awk 'NR==1 {print $NF}' | awk -F. '{print $1"."$2}')"
102-
fi
103-
;;
104-
105-
(SunOS)
106-
system_type="sunos"
107-
system_name="solaris"
108-
system_version="$(uname -v)"
109-
110-
if [[ "${system_version}" == joyent* ]]; then
111-
system_name="smartos"
112-
system_version="${system_version#* }"
113-
elif [[ "${system_version}" == oi* ]]; then
114-
system_name="openindiana"
115-
system_version="${system_version#* }"
116-
fi
18+
if [[ "\$1" == "-e" ]]; then
19+
case "\$2" in
20+
"puts Process.pid")
21+
echo \$BASHPID
11722
;;
118-
119-
(OpenBSD)
120-
system_type="bsd"
121-
system_name="openbsd"
122-
system_version="$(uname -r)"
23+
"puts Process.ppid")
24+
echo \$PPID
12325
;;
124-
125-
(Darwin)
126-
system_type="darwin"
127-
system_name="osx"
128-
system_version="$(sw_vers -productVersion)"
129-
system_version="${system_version%.*}" # only major.minor - teeny is ignored
130-
;;
131-
132-
(FreeBSD)
133-
system_type="bsd"
134-
system_name="freebsd"
135-
system_version="$(uname -r)"
136-
system_version="${system_version%%-*}"
26+
"print RUBY_VERSION")
27+
echo -n $test_ruby_version
13728
;;
138-
139-
(*)
140-
return 1
29+
*)
30+
echo "no stub for ruby express: \$2" >/dev/null
31+
exit -1
14132
;;
14233
esac
143-
144-
system_type="${system_type//[ \/]/_}"
145-
system_name="${system_name//[ \/]/_}"
146-
system_version="${system_version//[ \/]/_}"
147-
system_arch="${system_arch//[ \/]/_}"
148-
system_arch="${system_arch/amd64/x86_64}"
149-
system_arch="${system_arch/i[123456789]86/i386}"
150-
}
151-
152-
if [[ -x "${test_ruby_root}/bin/ruby" ]]; then
153-
exit
34+
else
35+
readarray -t input
36+
37+
for line in "\${input[@]}"; do
38+
if [[ "\$line" == *"puts \"export RUBY_ENGINE=#{Object.const_defined?(:RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'};\""* ]]; then
39+
echo "export RUBY_ENGINE=$test_ruby_engine;"
40+
fi
41+
42+
if [[ "\$line" == *"puts \"export RUBY_VERSION=#{RUBY_VERSION};\""* ]]; then
43+
echo "export RUBY_VERSION=$test_ruby_version;"
44+
fi
45+
46+
if [[ "\$line" == *"puts \"export GEM_ROOT=#{Gem.default_dir.inspect};\""* ]]; then
47+
echo "export GEM_ROOT=$test_gem_root;"
48+
fi
49+
done
15450
fi
155-
156-
157-
detect_system || fail "Cannot auto-detect system type"
158-
[[ "$system_name" == "unknown" ]] && fail "Could not detect system name"
159-
[[ "$system_version" == "unknown" ]] && fail "Could not detect system version"
160-
[[ "$system_arch" == "unknown" ]] && fail "Could not detect system arch"
161-
162-
test_ruby_archive="${test_ruby_engine}-${test_ruby_version}.tar.bz2"
163-
test_ruby_url="http://rvm.io/binaries/$system_name/$system_version/$system_arch/$test_ruby_archive"
164-
test_ruby_dirname="$test_ruby_engine-$test_ruby_version"
165-
166-
mkdir -p "$PWD/test/fixtures/root/opt/rubies"
167-
cd "$PWD/test/fixtures/root/opt/rubies"
168-
169-
log "Downloading $test_ruby_url ..."
170-
download "$test_ruby_url" "$test_ruby_archive" || fail "Download failed"
171-
172-
log "Unpacking $test_ruby_archive ..."
173-
tar -xjf "$test_ruby_archive" || fail "Unpacking failed"
174-
175-
log "Cleaning up ..."
176-
rm -f "$test_ruby_archive"
51+
EOF
52+
chmod +x "$ruby_dir/bin/ruby"

0 commit comments

Comments
 (0)