Permalink
Browse files

[osh2oil] Tests for here docs and the 'set' builtin.

Also, add a function to list all tests, and add more to the PASSING
list.
  • Loading branch information...
Andy Chu
Andy Chu committed Aug 26, 2018
1 parent a181a33 commit 007c4bdb0ec031407e7bd77c2f7e00e0fd932278
Showing with 101 additions and 42 deletions.
  1. +100 −39 test/osh2oil.sh
  2. +1 −3 tools/osh2oil.py
View
@@ -305,7 +305,29 @@ single quoted
'''
OIL
# TODO: <<-
# <<- is indented
osh0-oil3 << 'OSH' 3<< 'OIL'
cat <<-'ONE'
indented
body
ONE
OSH
cat << '''
indented
body
'''
OIL
}
here-string() {
osh0-oil3 << 'OSH' 3<< 'OIL'
cat <<< "double $foo"
cat <<< 'single'
OSH
cat << "double $foo"
cat << 'single'
OIL
}
more-env() {
@@ -326,45 +348,8 @@ env FOO=$(bar) BAR=$[echo hi] echo 2
OIL
}
assign2() {
osh0-oil3 << 'OSH' 3<< 'OIL'
foo=bar spam="$var"
OSH
setglobal foo = 'bar', spam = $var
OIL
osh0-oil3 << 'OSH' 3<< 'OIL'
readonly foo=bar spam="${var}"
OSH
const foo = 'bar', spam = $(var)
OIL
osh0-oil3 << 'OSH' 3<< 'OIL'
f() {
local foo=bar spam=eggs
foo=mutated
g=new
}
OSH
proc f {
var foo = 'bar', spam = 'eggs'
set foo = 'mutated'
setglobal g = 'new'
}
OIL
return
# Inside function
osh0-oil3 << 'OSH' 3<< 'OIL'
f() { foo=bar spam=${var:-default}; }
OSH
proc f { setglobal foo = 'bar', spam = $(var or 'default'); }
OIL
}
# NOTE: This is probably wrong
export-case() {
export-case() {
osh0-oil3 << 'OSH' 3<< 'OIL'
export foo=bar spam="${var}/const"
OSH
@@ -456,6 +441,44 @@ proc f {
OIL
}
assign2() {
osh0-oil3 << 'OSH' 3<< 'OIL'
foo=bar spam="$var"
OSH
setglobal foo = 'bar', spam = $var
OIL
osh0-oil3 << 'OSH' 3<< 'OIL'
readonly foo=bar spam="${var}"
OSH
const foo = 'bar', spam = $(var)
OIL
osh0-oil3 << 'OSH' 3<< 'OIL'
f() {
local foo=bar spam=eggs
foo=mutated
g=new
}
OSH
proc f {
var foo = 'bar', spam = 'eggs'
set foo = 'mutated'
setglobal g = 'new'
}
OIL
return
# Inside function
osh0-oil3 << 'OSH' 3<< 'OIL'
f() { foo=bar spam=${var:-default}; }
OSH
proc f { setglobal foo = 'bar', spam = $(var or 'default'); }
OIL
}
array-literal() {
osh0-oil3 << 'OSH' 3<< 'OIL'
a=(1 2 3)
@@ -494,6 +517,38 @@ not -- echo hi | wc
OIL
}
# 'set' is a keyword in Oil, so the multiple usages of 'set' builtin have to
# become something else.
builtin-set() {
# option is a keyword like setglobal? The RHS it optional; defaults to true?
osh0-oil3 << 'OSH' 3<< 'OIL'
set -o nounset
set +o errexit
OSH
option nounset
option errexit = false
OIL
# We could do:
# setoption nounset = true, errexit = false
# Accept old syntax too
osh0-oil3 << 'OSH' 3<< 'OIL'
set -o nounset -o pipefail +o errexit
OSH
sh-builtin set -o nounset -o pipefail +o errexit
OIL
# Mutating the arguments array is discouraged/deprecated in Oil. Just
# make a new first-class array instead of mutating the existing one.
osh0-oil3 << 'OSH' 3<< 'OIL'
set a b c
OSH
set -- a b c
OIL
}
and-or() {
osh0-oil3 << 'OSH' 3<< 'OIL'
ls && echo "$@" || die "foo"
@@ -957,6 +1012,8 @@ OIL
readonly -a PASSING=(
simple-command
assign
assign2
more-env
line-breaks
redirect
@@ -991,6 +1048,10 @@ readonly -a PASSING=(
bracket-builtin
)
list-all-tests() {
egrep '^[a-z0-9_\-]+\(\) {' $0
}
all-passing() {
run-all "${PASSING[@]}"
}
View
@@ -1,8 +1,6 @@
from __future__ import print_function
"""
fix.py -- Do source transformations. Somewhat like 'go fix'.
TODO: Change := to =, and var/const/set
osh2oil.py: Translate OSH to Oil.
"""
import sys

0 comments on commit 007c4bd

Please sign in to comment.