bsh project

This commit is contained in:
brice.boisson
2022-02-08 18:50:03 +01:00
commit 7744ceaa33
109 changed files with 9536 additions and 0 deletions

2
tests/alias.yml Normal file
View File

@@ -0,0 +1,2 @@
- name: Basic
file: tests/aliases/basic.sh

2
tests/aliases/basic.sh Normal file
View File

@@ -0,0 +1,2 @@
alias bar=ls
bar

View File

@@ -0,0 +1,5 @@
for i in ee oo kk; do
echo $i
break
done
echo "done"

View File

@@ -0,0 +1,12 @@
for i in ee oo uu;
echo $i
while echo 11; do
until grep; do
for j in aa bb cc;
echo $j
break 4
done
done
done
done
echo "done"

View File

@@ -0,0 +1,12 @@
for i in ee oo uu;
echo $i
while echo 11; do
until grep; do
for j in aa bb cc;
echo $j
break 5
done
done
done
done
echo "done"

35
tests/case.yml Normal file
View File

@@ -0,0 +1,35 @@
- name: exit in case
input: a=33; case 22 in ($a) echo oui;; (22) echo non; exit;; esac; echo oui
- name: basic
file: tests/case/basic.sh
- name: all_case
input: "case 'yoyoy' in bruh) echo error;; *) echo ayaya;; esac"
- name: no_match
input: "case 'yoyoy' in bruh) echo error;; efefefef) echo ayaya;; esac; echo 'this is the first line'"
- name: no_case_clause
input: "case 'yoyoy' in esac"
- name: no_ending_semicolons
input: "case 'yoyoy' in bruh) echo error;; yoyoy) echo ayaya; esac"
- name: case_in_case
input: "case test in test) case second in s) echo false;; (second) echo ok;; esac; echo woow!;; esac"
- name: hard_semicolon
input: "case test in bruh) echo error;; test) echo ayaya;; a) echo a; esac"
- name: if_in_case
input: "case test in bruh) echo error;; test) if true; then echo ok; fi;; a) echo a; esac"
- name: case_in_function
file: tests/case/case_in_function.sh
- name: if_in_case_in_if
file: tests/case/if_in_case_in_if.sh
- name: multiple_condition_case
file: tests/case/multiple_condition_case.sh

6
tests/case/basic.sh Normal file
View File

@@ -0,0 +1,6 @@
case test in
te)
echo wrong;;
"test")
echo ok ;;
esac

View File

@@ -0,0 +1,16 @@
fun()
{
case fun in
f)
echo nope;;
*)
echo nice;;
esac
}
case call in
call)
fun;;
c)
echo what?;;
esac

View File

@@ -0,0 +1,13 @@
a=true
if $a
then
case $a in
false)
echo false;;
(true)
echo $a;;
esac
fi
echo end

View File

@@ -0,0 +1,4 @@
case test in
te|test|aaaaaaaaa)
echo true;;
esac

59
tests/cd.yml Normal file
View File

@@ -0,0 +1,59 @@
- name: Basic folder
input: cd src; pwd
- name: Multiple folders
input: cd src; cd builtins; cd ..; pwd
- name: Long path
input: cd src/../tests/../; pwd
- name: Long path, doesn't work
input: cd src/builtins/Makefile/ ; pwd
- name: Wrong folder
input: cd jenexistepas; pwd
- name: File
input: cd Makefile; pwd
- name: Folder then a dash
input: cd src; cd -; pwd
- name: Root
input: cd ./; pwd
- name: Root then folder
input: cd ./src; pwd
- name: Root then folder then reroot
input: cd ./src; cd ./; pwd
- name: Root after folder
input: cd src/./; pwd
- name: Root then dash
input: cd ./; cd -; pwd
- name: Root folder then dash
input: cd ./src/builtins; cd -; pwd
- name: Root folder inexistant
input: cd ./jenexistepas; pwd
- name: Root folder is a file
input: cd ./Makefile; pwd
- name: Double root
input: cd ././; pwd
- name: Multiple dash
input: cd -----; pwd
- name: Chained dash
input: cd /tmp; cd /root; echo start; cd -; pwd; cd -; pwd; cd -; pwd; cd -; pwd; cd -; pwd; cd -; echo end; pwd
- name: Go back but too far
input: cd ../../../../../../../../../../../../../../tmp; pwd; cd /home; cd -; pwd;
- name: Go back (absolute) but too far
input: cd /../../../../../../../../../../../../../../tmp; pwd; cd /home; cd -; pwd;

View File

@@ -0,0 +1,8 @@
- name: Basic
file: tests/cmd_substitution/basic.sh
- name: Backticks
file: tests/cmd_substitution/backticks.sh
- name: With while loops
file: tests/cmd_substitution/with_while_loop.sh

View File

@@ -0,0 +1,4 @@
if `echo true`; then
echo ok
fi
`echo false`

View File

@@ -0,0 +1,3 @@
if $(echo true); then
echo ok
fi

View File

@@ -0,0 +1,3 @@
while $(echo false); do
echo nope
done

26
tests/command_list.yml Normal file
View File

@@ -0,0 +1,26 @@
- name: Two commands separated by semicolon
input: echo Hello; echo World!;
- name: Two commands, semicolon at the end
input: echo Hello; echo World!;
- name: Two commands, no space between semicolon and word
input: echo "Hello";echo "World!"
- name: Only semicolon
input: ;
- name: Many commands
input: ls;pwd;cat Makefile;echo "Test";
- name: Two semicolons
input: ;;
- name: One command and two semicolons
input: echo;;
- name: Many semicolons with 2 commands
input: echo salut;;;;; pwd;
- name: Wrong commands and multiple semicolons
input: a;a;a;a;;a;a;;;;a;;a;a;a;;a;

View File

@@ -0,0 +1,8 @@
- name: 1 break
file: tests/break_and_continue/1_break.sh
- name: 4 break
file: tests/break_and_continue/4_break.sh
- name: 5 break 4 loop
file: tests/break_and_continue/5_break_4_loop.sh

74
tests/echo.yml Normal file
View File

@@ -0,0 +1,74 @@
- name: Basic words
input: echo "Cut, Copy and Paste!"
- name: Basic -n
input: echo -n "Cut, Copy and Paste!"
- name: Basic words
input: echo "-n"
- name: Multiple Words
input: echo "Cut, Copy and Paste!" "Cut, Copy and Paste!"
- name: Multiple Words 2²
input: echo "Cut, Copy and Paste!" "Quentin" "Charles"
- name: Word without quote
input: echo nathan
- name: Sentence without quote
input: echo Je suis une phrase sans quote
- name: Sentence without quote with option
input: echo -n Je suis une phrase sans quote
- name: Sentence without quote with multiple spaces
input: echo Je suis une phrase sans quote
- name: Sentence without quote with multiple spaces with option
input: echo -n Je suis une phrase sans quote
- name: Sentence without quote with multiple spaces and a lost option
input: echo Je suis une -n phrase sans quote
- name: Echo empty
input: echo
- name: Echo empty with -n
input: echo -n
- name: Echo empty with -n and empty quote
input: echo -n ""
- name: Echo empty quote
input: echo ""
- name: Echo real backlash n
input: echo "\n"
- name: Echo wrong option
input: echo -a
- name: Echo wrong option followed by real one
input: echo -a -n
- name: Echo wrong option preceded by real one
input: echo -a -n
- name: Option in quote with word
input: echo "-n salut"
- name: Option in quote with word and mutliple spaces
input: echo "-n salut"
- name: Option in quote with no other word inside quote
input: echo "-n" "salut"
- name: Option in quote with space inside
input: echo "-n " "salut"
- name: Long argument
input: echo Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in
- name: 10 paragraphs
file: tests/echo/very_long.sh

19
tests/echo/very_long.sh Normal file
View File

@@ -0,0 +1,19 @@
echo "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque quam, varius et nunc nec, malesuada pellentesque risus. Morbi nunc augue, sollicitudin eu tincidunt id, vulputate quis nisl. Etiam quis risus id mauris blandit vestibulum. Suspendisse ullamcorper tortor id sapien iaculis, vel tincidunt orci consequat. Proin rhoncus dui ut accumsan tincidunt. Nullam luctus rutrum dui ut ornare. Fusce elit arcu, faucibus et nisl efficitur, dignissim commodo nibh. Nam imperdiet pretium massa, quis laoreet felis vestibulum maximus. Suspendisse imperdiet lacus vel diam feugiat molestie. Vestibulum et mauris porta est commodo porttitor. Curabitur egestas vitae sapien sit amet dignissim. Ut fringilla cursus urna non accumsan. Nullam vulputate id quam vel finibus. Morbi rutrum tincidunt venenatis. Curabitur lacus lectus, feugiat eget mi semper, pharetra aliquam arcu.
Sed semper tempor turpis non pretium. In vestibulum neque non risus vulputate ullamcorper. Proin mauris lectus, rhoncus at facilisis id, condimentum non est. Nulla purus velit, accumsan sit amet massa eu, auctor pulvinar lectus. Ut id justo sapien. Integer scelerisque, justo et aliquam malesuada, urna nisl bibendum magna, nec euismod justo leo id augue. Aliquam et velit eget enim pretium euismod. Nunc consectetur vel augue ac luctus. In porttitor vulputate lectus nec ultrices. Mauris elementum lectus id ligula convallis, semper dignissim urna ullamcorper. Praesent convallis nisl in tortor malesuada ornare. Quisque eu nulla finibus, blandit metus eu, porttitor purus. Donec vitae lacus nec turpis semper pellentesque non id tortor. Pellentesque quis libero sagittis, ultrices massa in, scelerisque est. Mauris semper dui turpis.
In finibus risus ac lorem pulvinar, et congue est eleifend. Curabitur finibus eu ante a rutrum. Sed mollis neque in finibus rhoncus. Praesent blandit maximus velit a ornare. Nunc suscipit ligula eget lacus posuere, vel egestas metus ornare. Vestibulum vel rutrum quam. Ut justo dolor, viverra in rhoncus sed, ultrices eget quam. Proin aliquet nunc sed aliquam tempus. Vivamus accumsan est sed libero aliquet interdum. Aenean rhoncus turpis in nisi vulputate pretium. Quisque vel accumsan nulla. Aliquam euismod massa eget dui semper aliquam. Proin massa nunc, placerat sed ante in, tincidunt convallis metus. Etiam quis sem lacinia velit condimentum lobortis suscipit non enim. Aliquam vel condimentum dui. Nunc eget pharetra odio.
Nam in purus tincidunt, porttitor turpis sit amet, pharetra velit. Nunc eu tempor ligula. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam a varius quam. Mauris nec cursus nisl. In velit tellus, cursus non mi sit amet, sagittis semper enim. Phasellus elementum purus nibh, vel finibus urna vulputate non. Aenean tortor nunc, faucibus et imperdiet eu, blandit at dui. Suspendisse tempor auctor sodales. Donec hendrerit nibh quis augue consequat, quis dapibus quam faucibus.
Cras maximus hendrerit velit non porta. In hac habitasse platea dictumst. Aliquam nec consectetur erat. Cras sodales sit amet dolor id congue. Mauris et aliquam risus, nec aliquam nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Sed sed turpis finibus, feugiat nibh vel, interdum ligula. Donec sit amet nunc rutrum, efficitur erat eu, mattis justo. Phasellus sit amet scelerisque ex. Suspendisse fringilla tempus risus, efficitur aliquet ex tincidunt eget.
Sed eleifend, odio vitae rutrum convallis, nisl dui mollis magna, a euismod erat elit quis erat. Phasellus convallis vulputate ante, a convallis risus. Curabitur imperdiet quam non aliquam tempor. Integer maximus lacus elit, vehicula pulvinar nunc elementum tincidunt. In tincidunt ante sit amet est aliquet porta. Pellentesque dictum egestas purus, sit amet lobortis ex tincidunt condimentum. Maecenas vulputate orci a diam fermentum, ac rutrum mauris pellentesque. In non blandit justo, in scelerisque sem.
Quisque lobortis pretium velit, sit amet sollicitudin tortor bibendum in. Integer posuere imperdiet erat, vel euismod mi mollis in. Donec felis nunc, dictum vitae sodales vel, suscipit vitae nisi. Nam convallis non ex ut facilisis. Nunc maximus facilisis arcu eget faucibus. Sed luctus orci sit amet commodo vestibulum. Donec est arcu, porta ac justo at, lobortis interdum felis. Sed finibus ante nec maximus mollis.
Nam tristique turpis quis congue suscipit. Nam vel tincidunt leo. Sed laoreet lectus nec ipsum dictum sollicitudin. Proin tincidunt sed augue sit amet posuere. Vestibulum vel rutrum nisl. Sed lectus nisl, lobortis eu lobortis vel, bibendum sed enim. Phasellus consectetur neque id tristique maximus. Donec quam sapien, rhoncus id maximus sit amet, bibendum vitae orci. Suspendisse potenti. Phasellus ut varius sapien. Vivamus facilisis in ligula nec accumsan. Phasellus sem neque, dictum et commodo vitae, vulputate nec ipsum. Pellentesque vitae tincidunt lorem.
Etiam dignissim lectus sed nunc elementum, quis ullamcorper turpis sodales. Pellentesque est sapien, cursus et est ut, posuere scelerisque diam. Nullam non nisi id ipsum elementum varius et ut magna. Donec laoreet quis tellus eu vehicula. Quisque et fermentum ligula. Nam rutrum sollicitudin mollis. Aliquam erat volutpat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse ullamcorper ut felis nec porttitor. Quisque scelerisque quis magna vel facilisis. Sed congue nisl id enim consectetur egestas. Suspendisse semper diam ex, sed vehicula neque maximus at. Maecenas sit amet ex vitae quam tristique vestibulum vel a tellus.
Praesent ultrices risus ut mauris auctor suscipit. In suscipit finibus massa, non finibus lacus ultricies sed. Vestibulum rutrum feugiat massa, at efficitur sapien volutpat blandit. Nunc eget erat sit amet libero ultricies ornare. Nunc imperdiet, magna a sodales tempor, mauris velit molestie velit, id interdum eros arcu quis odio. Quisque odio urna, auctor sit amet leo id, consequat vestibulum tellus. Etiam vulputate nunc eget turpis convallis iaculis. In nulla sapien, pretium ut sagittis id, eleifend sit amet nibh. Duis feugiat iaculis dapibus. Fusce blandit sapien id convallis faucibus. Phasellus suscipit mauris commodo bibendum condimentum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent aliquam fringilla mi. Sed et diam ipsum. Morbi ac ante id erat pretium congue eget id lectus. Proin laoreet augue eget est finibus, nec volutpat nulla porttitor."

29
tests/expansion.yml Normal file
View File

@@ -0,0 +1,29 @@
- name: basic variable
input: first=test; a="first value is $first"; echo "$a"
- name: basic variable no expand
input: first=test; a='first value is $first'; echo $a
- name: basic variable expand then no expand
input: first=test; a="first value is $first"; echo '$a $first'
- name: basic variable with weird quotes
input: first='test'; a="'first value is $first"; echo '"$a $first'
- name: basic variable with weird quotes reversed
input: first='test'; a="'first value is $first"; echo "'$a $first"
- name: basic variable with weird quotes escaped
input: first='test'; a="'first value is $first"; echo '\"$a $first'
- name: basic variable with undefined variable
input: first='test'; a='first value is $i $first'; echo "$a $first"
- name: basic variable with quotes in quotes
input: first=""; a='first value is $i $first'; echo "$a $first"
- name: wrong basic variable with quotes in quotes
input: first="""; a='first value is $i $first'; echo "$a $first"
- name: basic variable with undefined variable and weird quotes
input: first="$first"; a="'first value is "$first"'"; echo ''$a "$first''

17
tests/for.yml Normal file
View File

@@ -0,0 +1,17 @@
- name: Basic for
file: tests/for/basic.sh
- name: For in for
file: tests/for/for_in_for.sh
- name: For with variables
file: tests/for/for_in_variables.sh
- name: For mixed ';' and '\n'
file: tests/for/mixed.sh
- name: For no args no in
file: tests/for/no_args_no_in.sh
- name: Multiple for
file: tests/for/multiple.sh

4
tests/for/basic.sh Executable file
View File

@@ -0,0 +1,4 @@
for i in salut test
do
echo $i
done

9
tests/for/for_in_for.sh Normal file
View File

@@ -0,0 +1,9 @@
for i in salut mec
do
echo -n "$i "
for j in "bonjour" toi
do
echo -n $j
done
echo
done

View File

@@ -0,0 +1,6 @@
a=bonjour
b="encore un mot"
for i in $a $b
do
echo $i
done

3
tests/for/mixed.sh Normal file
View File

@@ -0,0 +1,3 @@
for i in salut toi je suis un for genial; do
echo $i
done

13
tests/for/multiple.sh Normal file
View File

@@ -0,0 +1,13 @@
for a in arg1 arg2 arg3
do
echo $a
done
for a in a b c d e f g
do
echo $a
done
for g in in for while; do
echo $g
done

8
tests/for/no_args_no_in.sh Executable file
View File

@@ -0,0 +1,8 @@
for salut
do
echo $salut
done
echo $?
echo $#
echo $@
echo $*

26
tests/functions.yml Normal file
View File

@@ -0,0 +1,26 @@
- name: Basic
file: ./tests/functions/basic.sh
- name: Arguments
file: tests/functions/arguments.sh
- name: Funtion in function
file: tests/functions/function_in_function.sh
- name: Arguments hard
file: tests/functions/arguments_hard.sh
- name: Mutilple calls with simple args
file: tests/functions/multiple_calls.sh
- name: Recursive calls
file: tests/functions/recursive_call.sh
- name: Declaration in if
file: tests/functions/declaration_in_if.sh
- name: Use function in other command
file: tests/functions/use_fun_in_other_cmd.sh
- name: Variable in function
file: tests/functions/variable_in_fun.sh

View File

@@ -0,0 +1,8 @@
foo()
{
echo $@
echo $#
echo $2
}
foo salut je suis un argument

View File

@@ -0,0 +1,9 @@
foo()
{
echo $@
}
foo arguments de la fonction
echo $@
foo "d'autres" arguments
exit 4

6
tests/functions/basic.sh Normal file
View File

@@ -0,0 +1,6 @@
foo()
{
echo "foo"
}
foo

View File

@@ -0,0 +1,8 @@
if true
then
foo() {
echo 'I am in foo function'
}
fi
foo

View File

@@ -0,0 +1,11 @@
foo()
{
bar()
{
echo "bar"
echo $@
}
}
foo salut je suis un argument
bar salut

View File

@@ -0,0 +1,9 @@
foo()
{
echo "this is a test"
echo $@
}
foo salut
foo
foo foo foo; foo a

View File

@@ -0,0 +1,11 @@
test()
{
if $@; then
test false
else
echo end
fi
}
test true
echo "did this work ?"

View File

@@ -0,0 +1,6 @@
fun() {
echo "fun"
}
echo fun
echo; fun

View File

@@ -0,0 +1,11 @@
a=12
fun()
{
a=42
echo "$a"
}
echo $a
fun
echo $a

67
tests/moulinette.py Normal file
View File

@@ -0,0 +1,67 @@
import argparse
from pathlib import Path
from difflib import unified_diff
import subprocess as sp
import yaml
from dataclasses import dataclass
@dataclass
class TestCase:
def __init__(self, name, input = None, file = None):
self.name = name
self.input = input
self.file = file
def diff(expected: str, actual: str) -> str:
expected_lines = expected.splitlines(keepends=True)
actual_lines = actual.splitlines(keepends=True)
return ''.join(unified_diff(actual_lines, expected_lines, fromfile='actual', tofile='expected'))
def run_shell(shell: str, stdin: str) -> sp.CompletedProcess:
return sp.run([shell], input=stdin, capture_output=True, text=True, env={})
def perform_check(expected: sp.CompletedProcess, actual: sp.CompletedProcess):
assert expected.returncode == actual.returncode, f"EXIT_CODE_ERR: expected {expected.returncode}, got {actual.returncode}"
assert expected.stdout == actual.stdout, f"STDOUT_ERR\n{diff(expected.stdout, actual.stdout)}"
assert len(expected.stderr) == len(actual.stderr) or (len(expected.stderr) != 0 and len(actual.stderr) != 0), f"STDERR_EMPTY"
if __name__ == '__main__':
parser = argparse.ArgumentParser("bshTestSuite")
parser.add_argument('--binary', required=True, type=Path)
parser.add_argument('--tests', required=True, nargs='+', default=[])
args = parser.parse_args()
binary_path = args.binary.absolute()
tests=0
errors=0
for test in args.tests:
with open(test, 'r') as file:
testsuite = [TestCase(**testcase) for testcase in yaml.safe_load(file)]
print(f"\033[6m## \033[0m\033[34m{test}\033[97m")
for testcase in testsuite:
tests += 1
input = testcase.input
if (testcase.file):
with open(testcase.file, 'r') as file:
input = file.read()
actual = run_shell(binary_path, input)
expected = run_shell("dash", input)
try:
perform_check(expected, actual)
except AssertionError as e:
print(f"\033[1m[ \033[31mKO\033[97m ] \033[0m{testcase.name}\n{e}")
errors += 1
else:
print(f"\033[1m[ \033[92mOK\033[97m ] \033[0m{testcase.name}")
print("")
if (errors > 1):
s = 's'
else:
s = ''
print(f"\n\033[33m✗ \033[34m{tests}\033[97m tests performed, \033[31m{errors}\033[97m error{s}\033[0m")
exit(errors)

35
tests/pipes.yml Normal file
View File

@@ -0,0 +1,35 @@
- name: basic
input: ls | grep Makefile
- name: double pipe
input: ls | grep Makefile | grep Makefile
- name: expand
input: a="Makefile"; ls | grep "$a"
- name: multiple file
input: ls -R src | grep src
- name: multiple file globing failed
input: ls -R src | grep *.c
- name: multiple file globing
input: ls -R src | grep .c
- name: pipe builtin pass
input: echo "test|pass" | grep pass
- name: pipe builtin pass
input: echo "test|pass" | grep failed
- name: 3 pipes
input: cat Makefile | grep "@" | grep "echo"
- name: most used
input: cat /root/.bash_history | cut -d' ' -f1 | sort | uniq -c | tr -s ' ' | cut -c 2- | sort -nr | head
- name: no builtins
input: ls | grep -E "*.c"
- name: mutltiple no builtins
input: ls | grep "s" | grep "bui"

1
tests/requirements.txt Normal file
View File

@@ -0,0 +1 @@
pyyaml

32
tests/reserved_words.yml Normal file
View File

@@ -0,0 +1,32 @@
- name: "Then and fi as arguments"
input: "if echo foo then echo bar fi; then echo 1; fi"
- name: "Bad command with then and fi as arguments"
input: "if echo foo then echo bar fi;"
- name: "Good command with then and else as arguments"
input: "if echo then; then echo else; fi"
- name: "Medium good command"
input: "if echo else; then if echo fi; then echo else; fi; fi"
- name: "Medium bad command with reserved word after then"
input: "if echo else; then if echo fi; then else echo test; fi; fi"
- name: "Medium bad command with reserved word after if"
input: "if fi; then if echo fi; then else echo test; fi; fi"
- name: "Medium bad command with reserved word after else"
input: "if echo fi; then if echo fi; then echo else; else fi; fi; fi"
- name: "Medium bad command with reserved word after elif"
input: "if echo fi; then if echo fi; then echo else; elif fi; else fi; fi; fi"
- name: "Medium good command with elif"
input: "if echo fi; then echo fi; elif echo fi; then echo else; else echo end; fi"
- name: "Medium bad command with elif"
input: "if echo fi; then echo fi; elif fi; then echo else; else echo end; fi"
- name: "Hard bad command with elif"
input: "if echo fi; then if echo else; then echo done; elif echo good; then echo elif; else echo test; fi; fi"

View File

@@ -0,0 +1,8 @@
- name: for adv 5
input: r=aaa; t='-$r-'; s="-$r-'"; elt=rr$r$t$s'oo$r 'oo" tt"pp" "; cat=ee${elt}ee; for i in "gg ""$cat"; do echo "$i"; done
- name: for adv 6
input: r=aaa; t='-$r-'; s="-$r-'"; elt=rr$r$t$s'oo$r 'oo" tt"pp" "; cat=ee${elt}ee; for i in 'gg '"$cat"; do echo "$i"; done
- name: mix non quote and quote
input: A=hello; echo $A'$A'\'$A\'

11
tests/subshells.yml Normal file
View File

@@ -0,0 +1,11 @@
- name: Basic
file: ./tests/subshells/basic.sh
- name: Subshell in subshell
file: ./tests/subshells/subshell_in_subshell.sh
- name: Function in subshell
file: ./tests/subshells/fun_in_subshell.sh
- name: Multiple variables
file: ./tests/subshells/multiple_variables.sh

3
tests/subshells/basic.sh Normal file
View File

@@ -0,0 +1,3 @@
a=21
(echo $a; a=42; echo $a)
echo $a

View File

@@ -0,0 +1,7 @@
fun()
{
echo "First fun"
}
(fun; fun() { echo "Second fun"; }; fun;)
fun;

View File

@@ -0,0 +1,9 @@
a=12
b=13
c=14
d=15
e=16
echo "$a $b $c $d $e"
(echo "$a $b $c $d $e"; a=21; c=41; e=61; echo "$a $b $c $d $e";)
echo "$a $b $c $d $e";

View File

@@ -0,0 +1,3 @@
a=12
(echo $a; a=13; (echo $a; a=42; echo $a); echo $a)
echo $a

65
tests/variable.yml Normal file
View File

@@ -0,0 +1,65 @@
- name: basic
input: a=ok; echo $a
- name: for basic
input: for i in yo lo; do echo $i; done
- name: for basic quotes
input: for i in 'yo' "lo"; do echo $i;; done
- name: for quotes with variable
input: a=12; for i in 'y$ao' "lo"; do echo $i; echo $a; done
- name: for quotes with variable 2
input: a=12; for i in 'y$ao' "l$ao"; do echo $i; echo $a; done
- name: for with double declaration
input: i=12; for i in 'yo' "lo"; do echo $i; done
- name: for with brackets variable
input: a=12; for i in 'y$ao' "l$ao"; do echo ${i}; echo $a; done
- name: for basic
input: for i in yo lo; do echo $i; done
- name: for adv 1
input: r=aaa; t='-$r-'; s="-$r-"; elt=rr$r$t$s'oo$r 'oo" tt"pp" "; cat=ee${elt}ee; for i in "gg" "$cat"; do echo "$i"; done
- name: for adv 2
input: r=aaa; t='-$r-'; s="-$r-'"; elt=rr$r$t$s'oo$r 'oo" tt"pp" "; cat=ee${elt}ee; for i in "gg" "$cat"; do echo "$i"; done
- name: for adv 3
input: r=aaa; t='-$r-'; s="-$r'-"; elt=rr$r$t$s'oo$r 'oo" tt"pp" "; cat=ee${elt}ee; for i in "gg" "$cat"; do echo "$i"; done
- name: for adv 4
input: r=aaa; t='-$r-'; s="-$r-"; elt=rr$r$t$s'oo$r 'oo" tt"pp" "; cat=ee${elt}ee; for i in "gg $cat"; do echo "$i"; done
- name: for adv 5
input: r=aaa; t='-$r-'; s="-$r-'"; elt=rr$r$t$s'oo$r 'oo" tt"pp" "; cat=ee${elt}ee; for i in "gg $cat"; do echo "$i"; done
- name: for space in list
input: for i in "ee oo"; do echo $i; done
- name: for space in list 2
input: a=22; for i in "ee oo" $a; do echo $i; done
# - name: name with \
# input: \$a=11; b=22; echo $\$a $b
- name: mix non quote and quote
input: A=hello; echo $A '$A' \'$A\'
- name: test special
input: echo $?
- name: test special end
input: a=22; echo $a?
- name: test special end 2
input: echo $?@
- name: only $
input: echo \n$
- name: only $ quoted
input: echo "\n$"

11
tests/wrong_commands.yml Normal file
View File

@@ -0,0 +1,11 @@
- name: Not found
input: eiyeriy
- name: Error during execution
input: cat eiodeiohjhrh
- name: Error during parsing
input: if echo test; else echo t
- name: Error during lexing
input: echo "eeee''