forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmdlineargs.jl
170 lines (145 loc) · 7.18 KB
/
cmdlineargs.jl
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
let exename = joinpath(JULIA_HOME, Base.julia_exename())
# --version
let v = split(readall(`$exename -v`), "julia version ")[end]
@test VERSION == VersionNumber(v)
end
@test readall(`$exename -v`) == readall(`$exename --version`)
# --help
@test startswith(readall(`$exename -h`), "julia [options] [program] [args...]")
@test startswith(readall(`$exename --help`), "julia [options] [program] [args...]")
# --quiet
# This flag is indirectly tested in test/repl.jl
# --home
@test success(`$exename -H $JULIA_HOME`)
@test success(`$exename --home=$JULIA_HOME`)
# --eval
@test success(`$exename -e "exit(0)"`)
@test !success(`$exename -e "exit(1)"`)
@test success(`$exename --eval="exit(0)"`)
@test !success(`$exename --eval="exit(1)"`)
@test !success(`$exename -e`)
@test !success(`$exename --eval`)
# --print
@test readall(`$exename -E "1+1"`) == "2\n"
@test readall(`$exename --print="1+1"`) == "2\n"
@test !success(`$exename -E`)
@test !success(`$exename --print`)
# --post-boot
@test success(`$exename -P "exit(0)"`)
@test !success(`$exename -P "exit(1)"`)
@test success(`$exename --post-boot="exit(0)"`)
@test !success(`$exename --post-boot="exit(1)"`)
@test !success(`$exename -P`)
@test !success(`$exename --post-boot`)
# --load
let testfile = tempname()
try
open(testfile, "w") do io
println(io, "testvar = :test")
end
@test split(readchomp(`$exename --load=$testfile -P "println(testvar)"`), '\n')[end] == "test"
@test split(readchomp(`$exename -P "println(testvar)" -L $testfile`), '\n')[end] == "test"
finally
rm(testfile)
end
end
# -L, --load requires an argument
@test !success(`$exename -L`)
@test !success(`$exename --load`)
# --cpu-target
@test !success(`$exename -C invalidtarget`)
@test !success(`$exename --cpu-target=invalidtarget`)
# --procs
@test readchomp(`$exename -q -p 2 -P "println(nworkers()); exit(0)"`) == "2"
@test !success(`$exename -p 0`)
@test !success(`$exename --procs=1.0`)
# --machinefile
# this does not check that machinefile works,
# only that the filename gets correctly passed to the option struct
let fname = tempname()
touch(fname)
try
@test readchomp(`$exename --machinefile $fname -e "println(bytestring(Base.JLOptions().machinefile))"`) == fname
finally
rm(fname)
end
end
# -i, isinteractive
@test readchomp(`$exename -E "isinteractive()"`) == "false"
@test readchomp(`$exename -E "isinteractive()" -i`) == "true"
# --color
@test readchomp(`$exename --color=yes -E "Base.have_color"`) == "true"
@test readchomp(`$exename --color=no -E "Base.have_color"`) == "false"
@test !success(`$exename --color=false`)
# --history-file
@test readchomp(`$exename -E "bool(Base.JLOptions().historyfile)" --history-file=yes`) == "true"
@test readchomp(`$exename -E "bool(Base.JLOptions().historyfile)" --history-file=no`) == "false"
# deprecated
@test readchomp(`$exename -E "bool(Base.JLOptions().historyfile)" --no-history-file`) == "false"
@test !success(`$exename --history-file=false`)
# --startup-file
let JL_OPTIONS_STARTUPFILE_ON = 1,
JL_OPTIONS_STARTUPFILE_OFF = 2
@test int(readchomp(`$exename -E "Base.JLOptions().startupfile" --startup-file=yes`)) == JL_OPTIONS_STARTUPFILE_ON
@test int(readchomp(`$exename -E "Base.JLOptions().startupfile" --startup-file=no`)) == JL_OPTIONS_STARTUPFILE_OFF
end
@test !success(`$exename --startup-file=false`)
# --code-coverage
@test readchomp(`$exename -E "bool(Base.JLOptions().code_coverage)"`) == "false"
@test readchomp(`$exename -E "bool(Base.JLOptions().code_coverage)" --code-coverage=none`) == "false"
@test readchomp(`$exename -E "bool(Base.JLOptions().code_coverage)" --code-coverage`) == "true"
@test readchomp(`$exename -E "bool(Base.JLOptions().code_coverage)" --code-coverage=user`) == "true"
# --track-allocation
@test readchomp(`$exename -E "bool(Base.JLOptions().malloc_log)"`) == "false"
@test readchomp(`$exename -E "bool(Base.JLOptions().malloc_log)" --track-allocation=none`) == "false"
@test readchomp(`$exename -E "bool(Base.JLOptions().malloc_log)" --track-allocation`) == "true"
@test readchomp(`$exename -E "bool(Base.JLOptions().malloc_log)" --track-allocation=user`) == "true"
# --optimize
@test readchomp(`$exename -E "bool(Base.JLOptions().opt_level)"`) == "false"
@test readchomp(`$exename -E "bool(Base.JLOptions().opt_level)" -O`) == "true"
@test readchomp(`$exename -E "bool(Base.JLOptions().opt_level)" --optimize`) == "true"
# --check-bounds
let JL_OPTIONS_CHECK_BOUNDS_DEFAULT = 0,
JL_OPTIONS_CHECK_BOUNDS_ON = 1,
JL_OPTIONS_CHECK_BOUNDS_OFF = 2
@test int(readchomp(`$exename -E "int(Base.JLOptions().check_bounds)"`)) == JL_OPTIONS_CHECK_BOUNDS_DEFAULT
@test int(readchomp(`$exename -E "int(Base.JLOptions().check_bounds)" --check-bounds=yes`)) == JL_OPTIONS_CHECK_BOUNDS_ON
@test int(readchomp(`$exename -E "int(Base.JLOptions().check_bounds)" --check-bounds=no`)) == JL_OPTIONS_CHECK_BOUNDS_OFF
end
# check-bounds takes yes/no as argument
@test !success(`$exename -E "exit(0)" --check-bounds=false`)
# --depwarn
@test readchomp(`$exename --depwarn=no -E "Base.syntax_deprecation_warnings(true)"`) == "false"
@test readchomp(`$exename --depwarn=yes -E "Base.syntax_deprecation_warnings(false)"`) == "true"
@test !success(`$exename --depwarn=false`)
# --inline
@test readchomp(`$exename -E "bool(Base.JLOptions().can_inline)"`) == "true"
@test readchomp(`$exename --inline=yes -E "bool(Base.JLOptions().can_inline)"`) == "true"
@test readchomp(`$exename --inline=no -E "bool(Base.JLOptions().can_inline)"`) == "false"
# --inline takes yes/no as arugment
@test !success(`$exename --inline=false`)
# --fast-math
let JL_OPTIONS_FAST_MATH_DEFAULT = 0,
JL_OPTIONS_FAST_MATH_OFF = 2
@test int(readchomp(`$exename -E "int(Base.JLOptions().fast_math)"`)) == JL_OPTIONS_FAST_MATH_DEFAULT
@test int(readchomp(`$exename --math-mode=user -E "int(Base.JLOptions().fast_math)"`)) == JL_OPTIONS_FAST_MATH_DEFAULT
@test int(readchomp(`$exename --math-mode=ieee -E "int(Base.JLOptions().fast_math)"`)) == JL_OPTIONS_FAST_MATH_OFF
end
# --math-mode takes ieee/user as argument
@test !success(`$exename --math-mode=fast`)
# --worker takes default / custom as arugment (default/custom arguments tested in test/parallel.jl, test/examples.jl)
@test !success(`$exename --worker=true`)
# test passing arguments
let testfile = tempname()
try
# write a julia source file that just prints ARGS to STDOUT and exits
open(testfile, "w") do io
println(io, "println(ARGS)")
end
@test readchomp(`$exename $testfile foo -bar --baz`) == "UTF8String[\"foo\",\"-bar\",\"--baz\"]"
@test !success(`$exename --foo $testfile`)
finally
rm(testfile)
end
end
end