-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.cr
54 lines (46 loc) · 1.27 KB
/
util.cr
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
require "compiler/crystal/syntax"
require "openssl"
require "process"
def tmp_dir(name : String)
if !File.directory?(name)
File.delete(name) rescue nil
temp_dir = File.tempname("fuzz", File.basename(name))
Dir.mkdir(temp_dir)
File.symlink(temp_dir, name)
end
return File.real_path(name)
end
RADAMSA_PORT = 31337
def get_input
TCPSocket.open("localhost", RADAMSA_PORT, &.gets_to_end)
end
def parse(src : String)
Crystal::Parser.new(src).parse
end
def run_process(
*args, output : Process::Redirect = :inherit, error : Process::Redirect = :inherit,
check = true, **kwargs
)
kwargs = {output: output, error: error}.merge(kwargs)
argv = args.to_a
r = Process.run(argv.shift, argv, **kwargs)
if check && !r.success?
raise "Process #{args} exited with status #{r.exit_status}"
end
return r
end
def start_process(
*args, output : Process::Redirect = :inherit, error : Process::Redirect = :inherit, **kwargs
)
kwargs = {output: output, error: error}.merge(kwargs)
args = args.to_a
Process.new(args.shift, args, **kwargs)
end
def crystal_repo
path = File.join(__DIR__, "crystal")
if !File.directory?(path)
tmp_dir(path)
run_process("git", "clone", "--depth=1", "https://github.com/crystal-lang/crystal", path)
end
return path
end