| 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 = 8; | 57 int argc = 7; |
| 58 const char* argv[] = { "Test2", "-notesting-bool-flag", | 58 const char* argv[] = { "Test2", "-notesting-bool-flag", "notaflag", |
| 59 "--notesting-maybe-bool-flag", "notaflag", | |
| 60 "--testing_int_flag=77", "-testing_float_flag=.25", | 59 "--testing_int_flag=77", "-testing_float_flag=.25", |
| 61 "--testing_string_flag", "no way!" }; | 60 "--testing_string_flag", "no way!" }; |
| 62 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, | 61 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, |
| 63 const_cast<char **>(argv), | 62 const_cast<char **>(argv), |
| 64 false)); | 63 false)); |
| 65 CHECK_EQ(8, argc); | 64 CHECK_EQ(7, argc); |
| 66 CHECK(!FLAG_testing_bool_flag); | 65 CHECK(!FLAG_testing_bool_flag); |
| 67 CHECK(FLAG_testing_maybe_bool_flag.has_value); | |
| 68 CHECK(!FLAG_testing_maybe_bool_flag.value); | |
| 69 CHECK_EQ(77, FLAG_testing_int_flag); | 66 CHECK_EQ(77, FLAG_testing_int_flag); |
| 70 CHECK_EQ(.25, FLAG_testing_float_flag); | 67 CHECK_EQ(.25, FLAG_testing_float_flag); |
| 71 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no way!")); | 68 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no way!")); |
| 72 } | 69 } |
| 73 | 70 |
| 74 | 71 |
| 75 TEST(Flags2b) { | 72 TEST(Flags2b) { |
| 76 SetFlagsToDefault(); | 73 SetFlagsToDefault(); |
| 77 const char* str = | 74 const char* str = |
| 78 " -notesting-bool-flag notaflag --testing_int_flag=77 " | 75 " -notesting-bool-flag notaflag --testing_int_flag=77 " |
| 79 "-notesting-maybe-bool-flag " | |
| 80 "-testing_float_flag=.25 " | 76 "-testing_float_flag=.25 " |
| 81 "--testing_string_flag no_way! "; | 77 "--testing_string_flag no_way! "; |
| 82 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); | 78 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); |
| 83 CHECK(!FLAG_testing_bool_flag); | 79 CHECK(!FLAG_testing_bool_flag); |
| 84 CHECK(FLAG_testing_maybe_bool_flag.has_value); | |
| 85 CHECK(!FLAG_testing_maybe_bool_flag.value); | |
| 86 CHECK_EQ(77, FLAG_testing_int_flag); | 80 CHECK_EQ(77, FLAG_testing_int_flag); |
| 87 CHECK_EQ(.25, FLAG_testing_float_flag); | 81 CHECK_EQ(.25, FLAG_testing_float_flag); |
| 88 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no_way!")); | 82 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no_way!")); |
| 89 } | 83 } |
| 90 | 84 |
| 91 | 85 |
| 92 TEST(Flags3) { | 86 TEST(Flags3) { |
| 93 SetFlagsToDefault(); | 87 SetFlagsToDefault(); |
| 94 int argc = 9; | 88 int argc = 8; |
| 95 const char* argv[] = | 89 const char* argv[] = |
| 96 { "Test3", "--testing_bool_flag", "--testing-maybe-bool-flag", "notaflag", | 90 { "Test3", "--testing_bool_flag", "notaflag", |
| 97 "--testing_int_flag", "-666", | 91 "--testing_int_flag", "-666", |
| 98 "--testing_float_flag", "-12E10", "-testing-string-flag=foo-bar" }; | 92 "--testing_float_flag", "-12E10", "-testing-string-flag=foo-bar" }; |
| 99 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, | 93 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, |
| 100 const_cast<char **>(argv), | 94 const_cast<char **>(argv), |
| 101 true)); | 95 true)); |
| 102 CHECK_EQ(2, argc); | 96 CHECK_EQ(2, argc); |
| 103 CHECK(FLAG_testing_bool_flag); | 97 CHECK(FLAG_testing_bool_flag); |
| 104 CHECK(FLAG_testing_maybe_bool_flag.has_value); | |
| 105 CHECK(FLAG_testing_maybe_bool_flag.value); | |
| 106 CHECK_EQ(-666, FLAG_testing_int_flag); | 98 CHECK_EQ(-666, FLAG_testing_int_flag); |
| 107 CHECK_EQ(-12E10, FLAG_testing_float_flag); | 99 CHECK_EQ(-12E10, FLAG_testing_float_flag); |
| 108 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar")); | 100 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar")); |
| 109 } | 101 } |
| 110 | 102 |
| 111 | 103 |
| 112 TEST(Flags3b) { | 104 TEST(Flags3b) { |
| 113 SetFlagsToDefault(); | 105 SetFlagsToDefault(); |
| 114 const char* str = | 106 const char* str = |
| 115 "--testing_bool_flag --testing-maybe-bool-flag notaflag " | 107 "--testing_bool_flag notaflag --testing_int_flag -666 " |
| 116 "--testing_int_flag -666 " | |
| 117 "--testing_float_flag -12E10 " | 108 "--testing_float_flag -12E10 " |
| 118 "-testing-string-flag=foo-bar"; | 109 "-testing-string-flag=foo-bar"; |
| 119 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); | 110 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); |
| 120 CHECK(FLAG_testing_bool_flag); | 111 CHECK(FLAG_testing_bool_flag); |
| 121 CHECK(FLAG_testing_maybe_bool_flag.has_value); | |
| 122 CHECK(FLAG_testing_maybe_bool_flag.value); | |
| 123 CHECK_EQ(-666, FLAG_testing_int_flag); | 112 CHECK_EQ(-666, FLAG_testing_int_flag); |
| 124 CHECK_EQ(-12E10, FLAG_testing_float_flag); | 113 CHECK_EQ(-12E10, FLAG_testing_float_flag); |
| 125 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar")); | 114 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar")); |
| 126 } | 115 } |
| 127 | 116 |
| 128 | 117 |
| 129 TEST(Flags4) { | 118 TEST(Flags4) { |
| 130 SetFlagsToDefault(); | 119 SetFlagsToDefault(); |
| 131 int argc = 3; | 120 int argc = 3; |
| 132 const char* argv[] = { "Test4", "--testing_bool_flag", "--foo" }; | 121 const char* argv[] = { "Test4", "--testing_bool_flag", "--foo" }; |
| 133 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, | 122 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, |
| 134 const_cast<char **>(argv), | 123 const_cast<char **>(argv), |
| 135 true)); | 124 true)); |
| 136 CHECK_EQ(2, argc); | 125 CHECK_EQ(2, argc); |
| 137 CHECK(!FLAG_testing_maybe_bool_flag.has_value); | |
| 138 } | 126 } |
| 139 | 127 |
| 140 | 128 |
| 141 TEST(Flags4b) { | 129 TEST(Flags4b) { |
| 142 SetFlagsToDefault(); | 130 SetFlagsToDefault(); |
| 143 const char* str = "--testing_bool_flag --foo"; | 131 const char* str = "--testing_bool_flag --foo"; |
| 144 CHECK_EQ(2, FlagList::SetFlagsFromString(str, StrLength(str))); | 132 CHECK_EQ(2, FlagList::SetFlagsFromString(str, StrLength(str))); |
| 145 CHECK(!FLAG_testing_maybe_bool_flag.has_value); | |
| 146 } | 133 } |
| 147 | 134 |
| 148 | 135 |
| 149 TEST(Flags5) { | 136 TEST(Flags5) { |
| 150 SetFlagsToDefault(); | 137 SetFlagsToDefault(); |
| 151 int argc = 2; | 138 int argc = 2; |
| 152 const char* argv[] = { "Test5", "--testing_int_flag=\"foobar\"" }; | 139 const char* argv[] = { "Test5", "--testing_int_flag=\"foobar\"" }; |
| 153 CHECK_EQ(1, FlagList::SetFlagsFromCommandLine(&argc, | 140 CHECK_EQ(1, FlagList::SetFlagsFromCommandLine(&argc, |
| 154 const_cast<char **>(argv), | 141 const_cast<char **>(argv), |
| 155 true)); | 142 true)); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 // if the list of arguments ends unexpectedly. | 238 // if the list of arguments ends unexpectedly. |
| 252 SetFlagsToDefault(); | 239 SetFlagsToDefault(); |
| 253 int argc = 3; | 240 int argc = 3; |
| 254 const char* argv[] = { "", "--crankshaft", "--expose-debug-as" }; | 241 const char* argv[] = { "", "--crankshaft", "--expose-debug-as" }; |
| 255 CHECK_EQ(2, FlagList::SetFlagsFromCommandLine(&argc, | 242 CHECK_EQ(2, FlagList::SetFlagsFromCommandLine(&argc, |
| 256 const_cast<char **>(argv), | 243 const_cast<char **>(argv), |
| 257 true)); | 244 true)); |
| 258 CHECK_NE(NULL, argv[1]); | 245 CHECK_NE(NULL, argv[1]); |
| 259 CHECK_EQ(argc, 2); | 246 CHECK_EQ(argc, 2); |
| 260 } | 247 } |
| OLD | NEW |