-
Notifications
You must be signed in to change notification settings - Fork 9
/
test.sh
executable file
·196 lines (157 loc) · 6.15 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env bash
set -euvo pipefail
dockerId=$1
err_report() {
echo "Error on line $1"
}
trap 'err_report $LINENO' ERR
grepOutput() {
local output_file="command_output.tmp"
if ! "${@:1:(($# - 1))}" &> $output_file
then
echo "Command failed!"
elif ! grep -q "${@:$#}" $output_file
then
echo "grep failed!"
else
rm $output_file
return 0
fi
cat $output_file
rm $output_file
exit 1
}
exactOutput() {
local output_file="command_output.tmp"
local expect_file="command_expect.tmp"
echo -n "${@:$#}" | xargs > $expect_file
if ! "${@:1:(($# - 1))}" | xargs > $output_file
then
echo "Command failed!"
elif ! diff -up $output_file $expect_file
then
echo "Output didn't match expected test"
else
rm $output_file
rm $expect_file
return 0
fi
cat $output_file
rm $output_file
rm $expect_file
exit 1
}
# simple hello world
source='void main() { import std.stdio; writeln("Hello World"); }'
bsource=$(echo $source | base64 -w0)
exactOutput docker run --rm $dockerId $bsource "Hello World"
# stdin
source='void main() { import std.algorithm, std.stdio; stdin.byLine.each!writeln;}'
bsource=$(echo $source | base64 -w0)
bstdin=$(printf 'Venus\nParis\nMontreal' | base64 -w0)
output="$(docker run --rm $dockerId $bsource $bstdin)"
[ "$(printf "$output" | head -n1)" == "Venus" ]
# custom arguments
source='void main() { import std.stdio; version(Foo) writeln("Hello World"); }'
bsource=$(echo $source | base64 -w0)
exactOutput env DOCKER_FLAGS="-version=Fooo" docker run -e DOCKER_FLAGS --rm $dockerId $bsource ""
[ "$(DOCKER_FLAGS="-version=Foo" docker run -e DOCKER_FLAGS --rm $dockerId $bsource)" != "Hello world" ]
[ "$(DOCKER_FLAGS="-version=Bar -version=Foo" docker run -e DOCKER_FLAGS --rm $dockerId $bsource)" != "Hello world" ]
# test runtime args
source='void main(string[] args) { import std.stdio; writeln(args[1..$]); }'
bsource=$(echo $source | base64 -w0)
exactOutput env DOCKER_RUNTIME_ARGS="foo -test=bar" docker run -e DOCKER_RUNTIME_ARGS --rm $dockerId $bsource "[\"foo\", \"-test=bar\"]"
## dub file
source='/++dub.sdl: name"foo"+/ void main() { import std.stdio; writeln("Hello World"); }'
bsource=$(echo "$source" | base64 -w0)
exactOutput docker run --rm $dockerId "$bsource" "Hello World"
source="/++dub.sdl: name\"foo\" \n dependency\"mir\" version=\"*\"+/ void main() { import mir.combinatorics, std.stdio; writeln([0, 1].permutations); }"
bsource=$(echo -e "$source" | base64 -w0)
grepOutput docker run --rm $dockerId "$bsource" "[[0, 1], [1, 0]]"
source="/++dub.sdl: name\"foo\" \n dependency\"vibe-d\" version=\">=0.9.7\"+/ void main() { import vibe.d, std.stdio; auto a = Json(\"hello world\"); a.writeln; }"
bsource=$(echo -e "$source" | base64 -w0)
grepOutput docker run --rm $dockerId "$bsource" "\"hello world\""
## dub file with unittest
source="/++dub.sdl: name\"foo\" \n dependency\"mir\" version=\"*\"+/ unittest { import mir.combinatorics, std.stdio; writeln([0, 1].permutations); } version(unittest) {} else { void main() { } } "
bsource=$(echo -e "$source" | base64 -w0)
grepOutput env DOCKER_FLAGS="-unittest" docker run -e DOCKER_FLAGS --rm $dockerId $bsource "[[0, 1], [1, 0]]"
# Test -c
source='void main() { static assert(0); }'
bsource=$(echo $source | base64 -w0)
# Test -vcg-ast
source='void main() { foreach (i; [1, 2]) {} }'
bsource=$(echo $source | base64 -w0)
grepOutput docker run -e DOCKER_FLAGS="-vcg-ast" --rm $dockerId $bsource "__key"
# Check -asm (DMD-only)
if [[ ! $dockerId =~ "ldc" ]] ; then
source='void main() { int a; }'
bsource=$(echo $source | base64 -w0)
grepOutput docker run -e DOCKER_FLAGS="-asm" --rm $dockerId $bsource "_Dmain"
fi
# Check -ouput-ll and -output-s
if [[ $dockerId =~ "ldc" ]] ; then
source='void main() { int a; }'
bsource=$(echo $source | base64 -w0)
grepOutput docker run -e DOCKER_FLAGS="-output-ll" --rm $dockerId $bsource 'define i32 @_Dmain'
grepOutput docker run -e DOCKER_FLAGS="-output-s" --rm $dockerId $bsource '_Dmain:'
fi
# Check AddressSanitizer output with line numbers (LDC-only)
if [[ $dockerId =~ "ldc" ]] ; then
source=$'void main() { \n int a; \n int* ap = &a + 1; \n *ap = 0; }'
# ^ line 4 column 2
bsource=$(echo "$source" | base64 -w0)
grepOutput docker run -e DOCKER_FLAGS="-fsanitize=address -g" --rm $dockerId $bsource '#0 0x[0-9a-f]* in ..main [/a-z\.]*:4:2'
fi
# Check HTML output
source='///\nvoid main(){}'
bsource=$(echo $source | base64 -w0)
grepOutput docker run -e DOCKER_FLAGS="-D" --rm $dockerId $bsource "<html>"
# Check JSON output
source='///\nvoid main(){}'
bsource=$(echo $source | base64 -w0)
grepOutput docker run -e DOCKER_FLAGS="-Xf=-" --rm $dockerId $bsource '"file" : "onlineapp.d"'
# Check Har
source="--- test.d\nvoid main(){import std.stdio; __FILE__.writeln;}"
bsource=$(echo -e "$source" | base64 -w0)
grepOutput docker run --rm $dockerId $bsource "test.d"
# Check har with multiple files
source="--- test.d\nvoid main(){import bar; foo();}\n--- bar.d\nvoid foo(){import std.stdio; __FILE__.writeln;}"
bsource=$(echo -e "$source" | base64 -w0)
grepOutput docker run --rm $dockerId $bsource "bar.d"
# Har - minimal runtime
# Only works on dmd-nightly for now
if [[ $1 = *nightly ]] ; then
source="--- object.d\nmodule object;\n--- bar.d\nextern(C) void main(){printf(\"%s\", __MODULE__.ptr);\n}"
bsource=$(echo -e "$source" | base64 -w0)
grepOutput docker run -e DOCKER_FLAGS="-conf= -defaultlib=" --rm $dockerId $bsource '`printf` is not defined'
fi
# Check dpp Hello World
source=$(cat <<EOF
#include <stdio.h>
void main() {
printf("Hello World");
}
EOF
)
bsource=$(echo "$source" | base64 -w0)
exactOutput docker run --rm $dockerId $bsource "Hello World"
# Check dpp Hello World with HAR
source=$(cat <<EOF
--- c.h
#ifndef C_H
#define C_H
#define FOO_ID(x) (x*3)
int twice(int i);
#endif
--- c.c
int twice(int i) { return i * 2; }
--- foo.dpp
#include "c.h"
void main() {
import std.stdio;
writeln(twice(FOO_ID(5))); // yes, it's using a C macro here!
}
EOF
)
bsource=$(echo "$source" | base64 -w0)
exactOutput docker run --rm $dockerId $bsource "30"