#    rpmmacro.at: test rpm macros
#
AT_BANNER([RPM macros])

# ------------------------------
AT_SETUP([simple rpm --eval])
AT_KEYWORDS([macros])
AT_CHECK([
runroot rpm --define "this that" --eval '%{this}'
],
[0],
[that
])
AT_CLEANUP

AT_SETUP([simple true conditional rpm --eval])
AT_KEYWORDS([macros])
AT_CHECK([
runroot rpm --define "this that" --eval '%{?this}'
],
[0],
[that
])
AT_CLEANUP

AT_SETUP([simple false conditional rpm --eval])
AT_KEYWORDS([macros])
AT_CHECK([
runroot rpm --define "this that" --eval '%{?that}'
],
[0],
[
])
AT_CLEANUP

AT_SETUP([uncompress macro])
AT_KEYWORDS([macros])
AT_CHECK([
runroot rpm \
    --define "__gzip /my/bin/gzip" \
    --eval "%{uncompress:/data/SOURCES/hello-2.0.tar.gz}"
],
[0],
[/my/bin/gzip -dc /data/SOURCES/hello-2.0.tar.gz
])
AT_CLEANUP

AT_SETUP([basename macro])
AT_KEYWORDS([macros])
AT_CHECK([
runroot rpm \
    --eval "%{basename:/data/SOURCES/hello-2.0.tar.gz}"
],
[0],
[hello-2.0.tar.gz
])
AT_CLEANUP

AT_SETUP([suffix macro])
AT_KEYWORDS([macros])
AT_CHECK([
runroot rpm \
    --eval "%{suffix:/data/SOURCES/hello-2.0.tar.gz}"
],
[0],
[gz
])
AT_CLEANUP

AT_SETUP([url2path macro])
AT_KEYWORDS([macros])
AT_CHECK([
runroot rpm \
    --eval "%{url2path:http://hello.org/releases/hello-2.0.tar.gz}"
],
[0],
[/releases/hello-2.0.tar.gz
])
AT_CLEANUP

AT_SETUP([shell expansion])
AT_KEYWORDS([macros])
AT_CHECK([
runroot rpm \
    --eval "%(echo foo)"
],
[0],
[foo
])
AT_CLEANUP

AT_SETUP([simple lua --eval])
AT_KEYWORDS([macros lua])
AT_CHECK([
runroot rpm --eval '%{lua:print(5*5)}'
],
[0],
[25
])
AT_CLEANUP

AT_SETUP([lua rpm extensions])
AT_KEYWORDS([macros lua])
AT_CHECK([
runroot rpm --eval '%{lua: rpm.define("foo bar") print(rpm.expand("%{foo}"))}'
],
[0],
[bar
])
AT_CLEANUP

AT_SETUP([lua posix extensions])
AT_KEYWORDS([macros lua])
AT_CHECK([
runroot rpm \
  --eval '%{lua: posix.putenv("LUATEST=ok") print(posix.getenv("LUATEST"))}'
],
[0],
[ok
])
AT_CLEANUP

AT_SETUP([lua script exit behavior])
AT_KEYWORDS([macros lua])
AT_CHECK([
runroot rpm \
  --eval '%{lua: os.exit()}))}'
],
[0],
[
],
[error: lua script failed: [[string "<lua>"]]:1: exit not permitted in this context]
)
AT_CLEANUP
