-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·88 lines (60 loc) · 4.28 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
NL=$'\n'
mkdir -p temp
[ "$(./shenv.sh)" == "" ] || echo 'FAIL: should not stdout anything when a .env is not present'
printf '%s' "KEY=value" > temp/.env
[ "$(./shenv.sh temp/.env)" == "export KEY=value" ] || echo 'FAIL: should be able to access env file with path when passed as an argument'
cd temp
printf '%s' "KEY=value" > .env
[ "$(../shenv.sh)" == "export KEY=value" ] || echo 'FAIL: should load default .env file when no arguments passed'
printf '%s' "KEY=value${NL}" > .env
[ "$(../shenv.sh)" == "export KEY=value" ] || echo 'FAIL: should not be affected by trailing whitespace'
printf '%s' "KEY_A=value${NL}KEY_B=value" > .env
[ "$(../shenv.sh)" == "export KEY_A=value${NL}export KEY_B=value" ] || echo 'FAIL: should load multiple env pairs'
printf '%s' "# KEY_A=value" > .env
[ "$(../shenv.sh)" == "" ] || echo 'FAIL: should not output commented lines'
printf '%s' "KEY_A=" > .env
[ "$(../shenv.sh)" == "export KEY_A=" ] || echo 'FAIL: should maintain empty values'
printf '%s' "KEY_A=Hello World" > .env
[ "$(../shenv.sh)" == 'export KEY_A=Hello\ World' ] || echo 'FAIL: should maintain space'
printf '%s' 'KEY_A= !"#$%&'"'"'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~' > .env
[ "$(../shenv.sh)" == 'export KEY_A=\ \!\"\#\$\%\&\'"'"'\(\)\*\+\,\-\.\/0123456789\:\;\<\=\>\?\@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\\\]\^\_\`abcdefghijklmnopqrstuvwxyz\{\|\}\~' ] || echo 'FAIL: should maintain all standard ascii characters (values 32 to 127)'
printf '%s' 'KEY_A=\n' > .env
[ "$(../shenv.sh)" == 'export KEY_A=\\n' ] || printf '%s\n' 'FAIL: should not treat \n as special when not double quoted'
printf '%s' 'KEY_A=""' > .env
[ "$(../shenv.sh)" == 'export KEY_A=' ] || echo 'FAIL: should have empty value for empty double quotes'
printf '%s' 'KEY_A="value"' > .env
[ "$(../shenv.sh)" == 'export KEY_A=value' ] || echo 'FAIL: should unwrap double quotes'
printf '%s' 'KEY_A="a\nb"' > .env
[ "$(../shenv.sh)" == "export KEY_A=a\$'\\n'b" ] || printf '%s\n' 'FAIL: should treat \n as newline when double quoted when in middle'
# haven't been able to get trailing \n to be converted into newline, can live without for now
# printf '%s' 'KEY_A="a\n"' > .env
# printf '%s\n%s\n' "$(cat .env)" "$(../shenv.sh)"
# [ "$(../shenv.sh)" == "export KEY_A=a\$'\\n'" ] || printf '%s\n' 'FAIL: should treat \n as newline when double quoted when at the end'
printf '%s' 'KEY_A="\nb"' > .env
[ "$(../shenv.sh)" == "export KEY_A=\$'\\n'b" ] || printf '%s\n' 'FAIL: should treat \n as newline when double quoted when at the start'
# haven't been able to get trailing \n to be converted into newline, can live without for now
# printf '%s' 'KEY_A="\n"' > .env
# printf '%s\n%s\n' "$(cat .env)" "$(../shenv.sh)"
# [ "$(../shenv.sh)" == "export KEY_A=\$'\\n'" ] || printf '%s\n' 'FAIL: should treat \n as newline when only it is double quoted'
printf '%s' "KEY_A='value'" > .env
[ "$(../shenv.sh)" == 'export KEY_A=value' ] || echo 'FAIL: should unwrap single quotes'
printf '%s' "KEY_A=''" > .env
[ "$(../shenv.sh)" == 'export KEY_A=' ] || echo 'FAIL: should have empty value for empty single quotes'
printf '%s' "KEY_A='\\n'" > .env
[ "$(../shenv.sh)" == 'export KEY_A=\\n' ] || printf '%s\n' 'FAIL: should not treat \n as special when single quoted'
printf '%s' 'KEY_A=한국어' > .env
[ "$(../shenv.sh)" == 'export KEY_A=\한\국\어' ] || echo 'FAIL: should handle unicode characters'
printf '%s' "${NL}${NL}KEY_A=value${NL}${NL}${NL}KEY_B=value${NL}${NL}${NL}" > .env
[ "$(../shenv.sh)" == "export KEY_A=value${NL}export KEY_B=value" ] || echo 'FAIL: should not be affected by empty lines"'
printf '%s' "${NL} ${NL}KEY_A=value${NL} ${NL}${NL}KEY_B=value${NL} ${NL}${NL}" > .env
[ "$(../shenv.sh)" == "export KEY_A=value${NL}export KEY_B=value" ] || echo 'FAIL: should not be affected by lines with spaces"'
printf '%s' "KEY_A=value${NL}KEY_B=value" > .env
printf '%s' "KEY_A=OTHER" > .env.other
[ "$(../shenv.sh .env.other)" == "export KEY_A=OTHER" ] || echo 'FAIL: should not be affected by existing default .env when an arguments is passed"'
printf '%s' "KEY_A=value${NL}KEY_B=value" > .env
printf '%s' "KEY_A=OTHER" > .env.other
[ "$(../shenv.sh .env.other)" == "export KEY_A=OTHER" ] || echo 'FAIL: should not be affected by existing default .env when an arguments is passed"'
cd ..
# cleanup
rm -r temp