summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmadeusz Żołnowski <aidecoe@gentoo.org>2016-05-18 23:29:46 +0100
committerAmadeusz Żołnowski <aidecoe@gentoo.org>2016-05-22 23:06:16 +0100
commit1c09a26ff45d4da33f9efce2950925ee917c9e0b (patch)
tree4e4f0745eb331c0b382534fb54ff7b8d4c64973e /eclass/tests
parentapp-portage/repoman: Add missed lxml dep for the 9999 ebuild (diff)
downloadgentoo-1c09a26ff45d4da33f9efce2950925ee917c9e0b.tar.gz
gentoo-1c09a26ff45d4da33f9efce2950925ee917c9e0b.tar.bz2
gentoo-1c09a26ff45d4da33f9efce2950925ee917c9e0b.zip
rebar.eclass: Build Erlang/OTP projects using dev-util/rebar
It is an eclass providing functions to build Erlang/OTP projects using dev-util/rebar. All packages in upcoming category dev-erlang are going to use this eclass.
Diffstat (limited to 'eclass/tests')
-rwxr-xr-xeclass/tests/rebar_fix_include_path.sh159
-rwxr-xr-xeclass/tests/rebar_remove_deps.sh99
-rwxr-xr-xeclass/tests/rebar_set_vsn.sh115
3 files changed, 373 insertions, 0 deletions
diff --git a/eclass/tests/rebar_fix_include_path.sh b/eclass/tests/rebar_fix_include_path.sh
new file mode 100755
index 000000000000..9047f8dcd225
--- /dev/null
+++ b/eclass/tests/rebar_fix_include_path.sh
@@ -0,0 +1,159 @@
+#!/bin/bash
+# Copyright 1999-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+source tests-common.sh
+
+EAPI=6
+
+inherit rebar
+
+EPREFIX="${tmpdir}/fakeroot"
+S="${WORKDIR}/${P}"
+
+setup() {
+ mkdir -p "${S}" || die
+
+ for pkg in foo-0.1.0 bar-0.1.0; do
+ mkdir -p "${EPREFIX}$(get_erl_libs)/${pkg}/include" || die
+ done
+
+ cat <<EOF >"${S}/typical.config" || die
+%%% Comment
+
+{erl_opts, [debug_info, {src_dirs, ["src"]},
+ {i, "include"},
+ {i, "deps/foo/include"},
+ {i, "../foo/include"}]}.
+
+{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
+EOF
+
+ cat <<EOF >"${S}/typical.config.expected" || die
+%%% Comment
+
+{erl_opts, [debug_info, {src_dirs, ["src"]},
+ {i, "include"},
+ {i, "${EPREFIX}$(get_erl_libs)/foo-0.1.0/include"},
+ {i, "../foo/include"}]}.
+
+{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
+EOF
+
+ cat <<EOF >"${S}/inc_one_line.config" || die
+%%% Comment
+
+{erl_opts, [debug_info, {src_dirs, ["src"]}, {i, "include"}, {i, "deps/foo/include"}, {i, "../foo/include"}]}.
+
+{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
+EOF
+
+ cat <<EOF >"${S}/inc_one_line.config.expected" || die
+%%% Comment
+
+{erl_opts, [debug_info, {src_dirs, ["src"]}, {i, "include"}, {i, "${EPREFIX}$(get_erl_libs)/foo-0.1.0/include"}, {i, "../foo/include"}]}.
+
+{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
+EOF
+}
+
+test_typical_config() {
+ local diff_rc
+ local unit_rc
+
+ # Prepare
+ cd "${S}" || die
+ cp typical.config rebar.config || die
+
+ # Run unit
+ (rebar_fix_include_path foo)
+ unit_rc=$?
+
+ # Test result
+ diff rebar.config typical.config.expected
+ diff_rc=$?
+
+ [[ ${unit_rc}${diff_rc} = 00 ]]
+}
+
+test_multiple_versions() {
+ local diff_rc
+ local unit_rc
+
+ # Prepare
+ cd "${S}" || die
+ cp typical.config rebar.config || die
+ mkdir -p "${EPREFIX}$(get_erl_libs)/foo-1.0.0/include" || die
+
+ # Run unit
+ (rebar_fix_include_path foo 2>/dev/null)
+ unit_rc=$?
+
+ # Test result
+ diff rebar.config typical.config
+ diff_rc=$?
+
+ # Clean up
+ rm -r "${EPREFIX}$(get_erl_libs)/foo-1.0.0" || die
+
+ [[ ${unit_rc}${diff_rc} = 10 ]]
+}
+
+test_not_found() {
+ local diff_rc
+ local unit_rc
+
+ # Prepare
+ cd "${S}" || die
+ cp typical.config rebar.config || die
+
+ # Run unit
+ (rebar_fix_include_path fo 2>/dev/null)
+ unit_rc=$?
+
+ # Test result
+ diff rebar.config typical.config
+ diff_rc=$?
+
+ [[ ${unit_rc}${diff_rc} = 10 ]]
+}
+
+test_includes_in_one_line() {
+ local diff_rc
+ local unit_rc
+
+ # Prepare
+ cd "${S}" || die
+ cp inc_one_line.config rebar.config || die
+
+ # Run unit
+ (rebar_fix_include_path foo)
+ unit_rc=$?
+
+ # Test result
+ diff rebar.config inc_one_line.config.expected
+ diff_rc=$?
+
+ [[ ${unit_rc}${diff_rc} = 00 ]]
+}
+
+setup
+
+tbegin "rebar_fix_include_path deals with typical config"
+test_typical_config
+tend $?
+
+tbegin "rebar_fix_include_path fails on multiple versions of dependency"
+test_multiple_versions
+tend $?
+
+tbegin "rebar_fix_include_path fails if dependency is not found"
+test_not_found
+tend $?
+
+tbegin "rebar_fix_include_path deals with all includes in one line"
+test_includes_in_one_line
+tend $?
+
+texit
diff --git a/eclass/tests/rebar_remove_deps.sh b/eclass/tests/rebar_remove_deps.sh
new file mode 100755
index 000000000000..05207a783cb4
--- /dev/null
+++ b/eclass/tests/rebar_remove_deps.sh
@@ -0,0 +1,99 @@
+#!/bin/bash
+# Copyright 1999-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+source tests-common.sh
+
+EAPI=6
+
+inherit rebar
+
+EPREFIX="${tmpdir}/fakeroot"
+S="${WORKDIR}/${P}"
+
+setup() {
+ mkdir -p "${S}" || die
+
+ cat <<EOF >"${S}/rebar.config.expected" || die
+%%% Comment
+
+{port_specs, [{"priv/lib/esip_drv.so", ["c_src/esip_codec.c"]}]}.
+
+{deps, []}.
+
+{clean_files, ["c_src/esip_codec.gcda", "c_src/esip_codec.gcno"]}.
+EOF
+
+ cat <<EOF >"${S}/typical.config" || die
+%%% Comment
+
+{port_specs, [{"priv/lib/esip_drv.so", ["c_src/esip_codec.c"]}]}.
+
+{deps, [{stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.0.3"}}},
+ {fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.3"}}},
+ {p1_utils, ".*", {git, "https://github.com/processone/p1_utils", {tag, "1.0.3"}}}]}.
+
+{clean_files, ["c_src/esip_codec.gcda", "c_src/esip_codec.gcno"]}.
+EOF
+
+ cat <<EOF >"${S}/deps_one_line.config" || die
+%%% Comment
+
+{port_specs, [{"priv/lib/esip_drv.so", ["c_src/esip_codec.c"]}]}.
+
+{deps, [{stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.0.3"}}}, {fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.3"}}}, {p1_utils, ".*", {git, "https://github.com/processone/p1_utils", {tag, "1.0.3"}}}]}.
+
+{clean_files, ["c_src/esip_codec.gcda", "c_src/esip_codec.gcno"]}.
+EOF
+}
+
+test_typical_config() {
+ local diff_rc
+ local unit_rc
+
+ # Prepare
+ cd "${S}" || die
+ cp typical.config rebar.config || die
+
+ # Run unit
+ (rebar_remove_deps)
+ unit_rc=$?
+
+ # Test result
+ diff rebar.config rebar.config.expected
+ diff_rc=$?
+
+ [[ ${unit_rc}${diff_rc} = 00 ]]
+}
+
+test_deps_in_one_line() {
+ local diff_rc
+ local unit_rc
+
+ # Prepare
+ cd "${S}" || die
+ cp deps_one_line.config rebar.config || die
+
+ # Run unit
+ (rebar_remove_deps)
+ unit_rc=$?
+
+ # Test result
+ diff rebar.config rebar.config.expected
+ diff_rc=$?
+
+ [[ ${unit_rc}${diff_rc} = 00 ]]
+}
+
+setup
+
+tbegin "rebar_remove_deps deals with typical config"
+test_typical_config
+tend $?
+
+tbegin "rebar_remove_deps deals with all deps in one line"
+test_deps_in_one_line
+tend $?
+
+texit
diff --git a/eclass/tests/rebar_set_vsn.sh b/eclass/tests/rebar_set_vsn.sh
new file mode 100755
index 000000000000..2a9f5bc92777
--- /dev/null
+++ b/eclass/tests/rebar_set_vsn.sh
@@ -0,0 +1,115 @@
+#!/bin/bash
+# Copyright 1999-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+source tests-common.sh
+
+EAPI=6
+
+inherit rebar
+
+EPREFIX="${tmpdir}/fakeroot"
+S="${WORKDIR}/${P}"
+
+setup() {
+ mkdir -p "${S}/src" || die
+
+ cat <<EOF >"${S}/app.src.expected" || die
+%%% Comment
+
+{application, esip,
+ [{description, "ProcessOne SIP server component in Erlang"},
+ {vsn, "0"},
+ {modules, []},
+ {registered, []},
+EOF
+
+ cat <<EOF >"${S}/app.src" || die
+%%% Comment
+
+{application, esip,
+ [{description, "ProcessOne SIP server component in Erlang"},
+ {vsn, git},
+ {modules, []},
+ {registered, []},
+EOF
+}
+
+test_typical_app_src() {
+ local diff_rc
+ local unit_rc
+
+ # Prepare
+ cd "${S}" || die
+ cp app.src "src/${PN}.app.src" || die
+
+ # Run unit
+ (rebar_set_vsn)
+ unit_rc=$?
+
+ # Test result
+ diff "src/${PN}.app.src" app.src.expected
+ diff_rc=$?
+
+ [[ ${unit_rc}${diff_rc} = 00 ]]
+}
+
+test_app_src_missing() {
+ local unit_rc
+
+ # Prepare
+ cd "${S}" || die
+ rm -f "src/${PN}.app.src" || die
+
+ # Run unit
+ (rebar_set_vsn 2>/dev/null)
+ unit_rc=$?
+
+ [[ ${unit_rc} = 1 ]]
+}
+
+test_set_custom_version() {
+ local diff_rc
+ local unit_rc
+
+ # Prepare
+ cd "${S}" || die
+ cp app.src "src/${PN}.app.src" || die
+ cat <<EOF >"${S}/custom_app.src.expected" || die
+%%% Comment
+
+{application, esip,
+ [{description, "ProcessOne SIP server component in Erlang"},
+ {vsn, "1.2.3"},
+ {modules, []},
+ {registered, []},
+EOF
+
+ # Run unit
+ (rebar_set_vsn 1.2.3)
+ unit_rc=$?
+
+ # Test result
+ diff "src/${PN}.app.src" custom_app.src.expected
+ diff_rc=$?
+
+ [[ ${unit_rc}${diff_rc} = 00 ]]
+}
+
+
+setup
+
+tbegin "rebar_set_vsn deals with typical app.src"
+test_typical_app_src
+tend $?
+
+tbegin "rebar_set_vsn fails when app.src is missing"
+test_app_src_missing
+tend $?
+
+tbegin "rebar_set_vsn sets custom version in app.src"
+test_set_custom_version
+tend $?
+
+texit