OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } | 47 } |
48 | 48 |
49 | 49 |
50 TEST(Flags1) { | 50 TEST(Flags1) { |
51 FlagList::PrintHelp(); | 51 FlagList::PrintHelp(); |
52 } | 52 } |
53 | 53 |
54 | 54 |
55 TEST(Flags2) { | 55 TEST(Flags2) { |
56 SetFlagsToDefault(); | 56 SetFlagsToDefault(); |
57 int argc = 7; | 57 int argc = 8; |
58 const char* argv[] = { "Test2", "-notesting-bool-flag", "notaflag", | 58 const char* argv[] = { "Test2", "-notesting-bool-flag", |
| 59 "--notesting-maybe-bool-flag", "notaflag", |
59 "--testing_int_flag=77", "-testing_float_flag=.25", | 60 "--testing_int_flag=77", "-testing_float_flag=.25", |
60 "--testing_string_flag", "no way!" }; | 61 "--testing_string_flag", "no way!" }; |
61 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, | 62 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, |
62 const_cast<char **>(argv), | 63 const_cast<char **>(argv), |
63 false)); | 64 false)); |
64 CHECK_EQ(7, argc); | 65 CHECK_EQ(8, argc); |
65 CHECK(!FLAG_testing_bool_flag); | 66 CHECK(!FLAG_testing_bool_flag); |
| 67 CHECK(FLAG_testing_maybe_bool_flag.has_value); |
| 68 CHECK(!FLAG_testing_maybe_bool_flag.value); |
66 CHECK_EQ(77, FLAG_testing_int_flag); | 69 CHECK_EQ(77, FLAG_testing_int_flag); |
67 CHECK_EQ(.25, FLAG_testing_float_flag); | 70 CHECK_EQ(.25, FLAG_testing_float_flag); |
68 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no way!")); | 71 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no way!")); |
69 } | 72 } |
70 | 73 |
71 | 74 |
72 TEST(Flags2b) { | 75 TEST(Flags2b) { |
73 SetFlagsToDefault(); | 76 SetFlagsToDefault(); |
74 const char* str = | 77 const char* str = |
75 " -notesting-bool-flag notaflag --testing_int_flag=77 " | 78 " -notesting-bool-flag notaflag --testing_int_flag=77 " |
| 79 "-notesting-maybe-bool-flag " |
76 "-testing_float_flag=.25 " | 80 "-testing_float_flag=.25 " |
77 "--testing_string_flag no_way! "; | 81 "--testing_string_flag no_way! "; |
78 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); | 82 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); |
79 CHECK(!FLAG_testing_bool_flag); | 83 CHECK(!FLAG_testing_bool_flag); |
| 84 CHECK(FLAG_testing_maybe_bool_flag.has_value); |
| 85 CHECK(!FLAG_testing_maybe_bool_flag.value); |
80 CHECK_EQ(77, FLAG_testing_int_flag); | 86 CHECK_EQ(77, FLAG_testing_int_flag); |
81 CHECK_EQ(.25, FLAG_testing_float_flag); | 87 CHECK_EQ(.25, FLAG_testing_float_flag); |
82 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no_way!")); | 88 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no_way!")); |
83 } | 89 } |
84 | 90 |
85 | 91 |
86 TEST(Flags3) { | 92 TEST(Flags3) { |
87 SetFlagsToDefault(); | 93 SetFlagsToDefault(); |
88 int argc = 8; | 94 int argc = 9; |
89 const char* argv[] = | 95 const char* argv[] = |
90 { "Test3", "--testing_bool_flag", "notaflag", | 96 { "Test3", "--testing_bool_flag", "--testing-maybe-bool-flag", "notaflag", |
91 "--testing_int_flag", "-666", | 97 "--testing_int_flag", "-666", |
92 "--testing_float_flag", "-12E10", "-testing-string-flag=foo-bar" }; | 98 "--testing_float_flag", "-12E10", "-testing-string-flag=foo-bar" }; |
93 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, | 99 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, |
94 const_cast<char **>(argv), | 100 const_cast<char **>(argv), |
95 true)); | 101 true)); |
96 CHECK_EQ(2, argc); | 102 CHECK_EQ(2, argc); |
97 CHECK(FLAG_testing_bool_flag); | 103 CHECK(FLAG_testing_bool_flag); |
| 104 CHECK(FLAG_testing_maybe_bool_flag.has_value); |
| 105 CHECK(FLAG_testing_maybe_bool_flag.value); |
98 CHECK_EQ(-666, FLAG_testing_int_flag); | 106 CHECK_EQ(-666, FLAG_testing_int_flag); |
99 CHECK_EQ(-12E10, FLAG_testing_float_flag); | 107 CHECK_EQ(-12E10, FLAG_testing_float_flag); |
100 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar")); | 108 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar")); |
101 } | 109 } |
102 | 110 |
103 | 111 |
104 TEST(Flags3b) { | 112 TEST(Flags3b) { |
105 SetFlagsToDefault(); | 113 SetFlagsToDefault(); |
106 const char* str = | 114 const char* str = |
107 "--testing_bool_flag notaflag --testing_int_flag -666 " | 115 "--testing_bool_flag --testing-maybe-bool-flag notaflag " |
| 116 "--testing_int_flag -666 " |
108 "--testing_float_flag -12E10 " | 117 "--testing_float_flag -12E10 " |
109 "-testing-string-flag=foo-bar"; | 118 "-testing-string-flag=foo-bar"; |
110 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); | 119 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); |
111 CHECK(FLAG_testing_bool_flag); | 120 CHECK(FLAG_testing_bool_flag); |
| 121 CHECK(FLAG_testing_maybe_bool_flag.has_value); |
| 122 CHECK(FLAG_testing_maybe_bool_flag.value); |
112 CHECK_EQ(-666, FLAG_testing_int_flag); | 123 CHECK_EQ(-666, FLAG_testing_int_flag); |
113 CHECK_EQ(-12E10, FLAG_testing_float_flag); | 124 CHECK_EQ(-12E10, FLAG_testing_float_flag); |
114 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar")); | 125 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar")); |
115 } | 126 } |
116 | 127 |
117 | 128 |
118 TEST(Flags4) { | 129 TEST(Flags4) { |
119 SetFlagsToDefault(); | 130 SetFlagsToDefault(); |
120 int argc = 3; | 131 int argc = 3; |
121 const char* argv[] = { "Test4", "--testing_bool_flag", "--foo" }; | 132 const char* argv[] = { "Test4", "--testing_bool_flag", "--foo" }; |
122 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, | 133 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, |
123 const_cast<char **>(argv), | 134 const_cast<char **>(argv), |
124 true)); | 135 true)); |
125 CHECK_EQ(2, argc); | 136 CHECK_EQ(2, argc); |
| 137 CHECK(!FLAG_testing_maybe_bool_flag.has_value); |
126 } | 138 } |
127 | 139 |
128 | 140 |
129 TEST(Flags4b) { | 141 TEST(Flags4b) { |
130 SetFlagsToDefault(); | 142 SetFlagsToDefault(); |
131 const char* str = "--testing_bool_flag --foo"; | 143 const char* str = "--testing_bool_flag --foo"; |
132 CHECK_EQ(2, FlagList::SetFlagsFromString(str, StrLength(str))); | 144 CHECK_EQ(2, FlagList::SetFlagsFromString(str, StrLength(str))); |
| 145 CHECK(!FLAG_testing_maybe_bool_flag.has_value); |
133 } | 146 } |
134 | 147 |
135 | 148 |
136 TEST(Flags5) { | 149 TEST(Flags5) { |
137 SetFlagsToDefault(); | 150 SetFlagsToDefault(); |
138 int argc = 2; | 151 int argc = 2; |
139 const char* argv[] = { "Test5", "--testing_int_flag=\"foobar\"" }; | 152 const char* argv[] = { "Test5", "--testing_int_flag=\"foobar\"" }; |
140 CHECK_EQ(1, FlagList::SetFlagsFromCommandLine(&argc, | 153 CHECK_EQ(1, FlagList::SetFlagsFromCommandLine(&argc, |
141 const_cast<char **>(argv), | 154 const_cast<char **>(argv), |
142 true)); | 155 true)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 SetFlagsToDefault(); | 187 SetFlagsToDefault(); |
175 int argc = 6; | 188 int argc = 6; |
176 const char* argv[] = {"TestJSArgs1", | 189 const char* argv[] = {"TestJSArgs1", |
177 "--testing-int-flag", "42", | 190 "--testing-int-flag", "42", |
178 "--", "testing-float-flag", "7"}; | 191 "--", "testing-float-flag", "7"}; |
179 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, | 192 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, |
180 const_cast<char **>(argv), | 193 const_cast<char **>(argv), |
181 true)); | 194 true)); |
182 CHECK_EQ(42, FLAG_testing_int_flag); | 195 CHECK_EQ(42, FLAG_testing_int_flag); |
183 CHECK_EQ(2.5, FLAG_testing_float_flag); | 196 CHECK_EQ(2.5, FLAG_testing_float_flag); |
184 CHECK_EQ(2, FLAG_js_arguments.argc()); | 197 CHECK_EQ(2, FLAG_js_arguments.argc); |
185 CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag")); | 198 CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag")); |
186 CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7")); | 199 CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7")); |
187 CHECK_EQ(1, argc); | 200 CHECK_EQ(1, argc); |
188 } | 201 } |
189 | 202 |
190 | 203 |
191 TEST(FlagsJSArguments1b) { | 204 TEST(FlagsJSArguments1b) { |
192 SetFlagsToDefault(); | 205 SetFlagsToDefault(); |
193 const char* str = "--testing-int-flag 42 -- testing-float-flag 7"; | 206 const char* str = "--testing-int-flag 42 -- testing-float-flag 7"; |
194 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); | 207 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); |
195 CHECK_EQ(42, FLAG_testing_int_flag); | 208 CHECK_EQ(42, FLAG_testing_int_flag); |
196 CHECK_EQ(2.5, FLAG_testing_float_flag); | 209 CHECK_EQ(2.5, FLAG_testing_float_flag); |
197 CHECK_EQ(2, FLAG_js_arguments.argc()); | 210 CHECK_EQ(2, FLAG_js_arguments.argc); |
198 CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag")); | 211 CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag")); |
199 CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7")); | 212 CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7")); |
200 } | 213 } |
201 | 214 |
202 | 215 |
203 TEST(FlagsJSArguments2) { | 216 TEST(FlagsJSArguments2) { |
204 SetFlagsToDefault(); | 217 SetFlagsToDefault(); |
205 const char* str = "--testing-int-flag 42 --js-arguments testing-float-flag 7"; | 218 const char* str = "--testing-int-flag 42 --js-arguments testing-float-flag 7"; |
206 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); | 219 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); |
207 CHECK_EQ(42, FLAG_testing_int_flag); | 220 CHECK_EQ(42, FLAG_testing_int_flag); |
208 CHECK_EQ(2.5, FLAG_testing_float_flag); | 221 CHECK_EQ(2.5, FLAG_testing_float_flag); |
209 CHECK_EQ(2, FLAG_js_arguments.argc()); | 222 CHECK_EQ(2, FLAG_js_arguments.argc); |
210 CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag")); | 223 CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag")); |
211 CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7")); | 224 CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7")); |
212 } | 225 } |
213 | 226 |
214 | 227 |
215 TEST(FlagsJSArguments3) { | 228 TEST(FlagsJSArguments3) { |
216 SetFlagsToDefault(); | 229 SetFlagsToDefault(); |
217 const char* str = "--testing-int-flag 42 --js-arguments=testing-float-flag 7"; | 230 const char* str = "--testing-int-flag 42 --js-arguments=testing-float-flag 7"; |
218 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); | 231 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); |
219 CHECK_EQ(42, FLAG_testing_int_flag); | 232 CHECK_EQ(42, FLAG_testing_int_flag); |
220 CHECK_EQ(2.5, FLAG_testing_float_flag); | 233 CHECK_EQ(2.5, FLAG_testing_float_flag); |
221 CHECK_EQ(2, FLAG_js_arguments.argc()); | 234 CHECK_EQ(2, FLAG_js_arguments.argc); |
222 CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag")); | 235 CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag")); |
223 CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7")); | 236 CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7")); |
224 } | 237 } |
225 | 238 |
226 | 239 |
227 TEST(FlagsJSArguments4) { | 240 TEST(FlagsJSArguments4) { |
228 SetFlagsToDefault(); | 241 SetFlagsToDefault(); |
229 const char* str = "--testing-int-flag 42 --"; | 242 const char* str = "--testing-int-flag 42 --"; |
230 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); | 243 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); |
231 CHECK_EQ(42, FLAG_testing_int_flag); | 244 CHECK_EQ(42, FLAG_testing_int_flag); |
232 CHECK_EQ(0, FLAG_js_arguments.argc()); | 245 CHECK_EQ(0, FLAG_js_arguments.argc); |
233 } | 246 } |
234 | 247 |
235 | 248 |
236 TEST(FlagsRemoveIncomplete) { | 249 TEST(FlagsRemoveIncomplete) { |
237 // Test that processed command line arguments are removed, even | 250 // Test that processed command line arguments are removed, even |
238 // if the list of arguments ends unexpectedly. | 251 // if the list of arguments ends unexpectedly. |
239 SetFlagsToDefault(); | 252 SetFlagsToDefault(); |
240 int argc = 3; | 253 int argc = 3; |
241 const char* argv[] = { "", "--crankshaft", "--expose-debug-as" }; | 254 const char* argv[] = { "", "--crankshaft", "--expose-debug-as" }; |
242 CHECK_EQ(2, FlagList::SetFlagsFromCommandLine(&argc, | 255 CHECK_EQ(2, FlagList::SetFlagsFromCommandLine(&argc, |
243 const_cast<char **>(argv), | 256 const_cast<char **>(argv), |
244 true)); | 257 true)); |
245 CHECK_NE(NULL, argv[1]); | 258 CHECK_NE(NULL, argv[1]); |
246 CHECK_EQ(argc, 2); | 259 CHECK_EQ(argc, 2); |
247 } | 260 } |
OLD | NEW |