OLD | NEW |
(Empty) | |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 #include "cctest.h" |
| 29 #include <stdio.h> |
| 30 #include <stdlib.h> |
| 31 #include <string.h> |
| 32 |
| 33 |
| 34 CcTest* CcTest::last_ = NULL; |
| 35 |
| 36 |
| 37 CcTest::CcTest(TestFunction* callback, const char* file, const char* name, |
| 38 const char* dependency, bool enabled) |
| 39 : callback_(callback), name_(name), dependency_(dependency), prev_(last_) { |
| 40 // Find the base name of this test (const_cast required on Windows). |
| 41 char *basename = strrchr(const_cast<char *>(file), '/'); |
| 42 if (!basename) { |
| 43 basename = strrchr(const_cast<char *>(file), '\\'); |
| 44 } |
| 45 if (!basename) { |
| 46 basename = strdup(file); |
| 47 } else { |
| 48 basename = strdup(basename + 1); |
| 49 } |
| 50 // Drop the extension, if there is one. |
| 51 char *extension = strrchr(basename, '.'); |
| 52 if (extension) *extension = 0; |
| 53 // Install this test in the list of tests |
| 54 file_ = basename; |
| 55 enabled_ = enabled; |
| 56 prev_ = last_; |
| 57 last_ = this; |
| 58 } |
| 59 |
| 60 |
| 61 static void PrintTestList(CcTest* current) { |
| 62 if (current == NULL) return; |
| 63 PrintTestList(current->prev()); |
| 64 if (current->dependency() != NULL) { |
| 65 printf("%s/%s<%s\n", |
| 66 current->file(), current->name(), current->dependency()); |
| 67 } else { |
| 68 printf("%s/%s<\n", current->file(), current->name()); |
| 69 } |
| 70 } |
| 71 |
| 72 |
| 73 int main(int argc, char* argv[]) { |
| 74 int tests_run = 0; |
| 75 bool print_run_count = true; |
| 76 for (int i = 1; i < argc; i++) { |
| 77 char* arg = argv[i]; |
| 78 if (strcmp(arg, "--list") == 0) { |
| 79 PrintTestList(CcTest::last()); |
| 80 print_run_count = false; |
| 81 |
| 82 } else { |
| 83 char* arg_copy = strdup(arg); |
| 84 char* testname = strchr(arg_copy, '/'); |
| 85 if (testname) { |
| 86 // Split the string in two by nulling the slash and then run |
| 87 // exact matches. |
| 88 *testname = 0; |
| 89 char* file = arg_copy; |
| 90 char* name = testname + 1; |
| 91 CcTest* test = CcTest::last(); |
| 92 while (test != NULL) { |
| 93 if (test->enabled() |
| 94 && strcmp(test->file(), file) == 0 |
| 95 && strcmp(test->name(), name) == 0) { |
| 96 test->Run(); |
| 97 tests_run++; |
| 98 } |
| 99 test = test->prev(); |
| 100 } |
| 101 |
| 102 } else { |
| 103 // Run all tests with the specified file or test name. |
| 104 char* file_or_name = arg_copy; |
| 105 CcTest* test = CcTest::last(); |
| 106 while (test != NULL) { |
| 107 if (test->enabled() |
| 108 && (strcmp(test->file(), file_or_name) == 0 |
| 109 || strcmp(test->name(), file_or_name) == 0)) { |
| 110 test->Run(); |
| 111 tests_run++; |
| 112 } |
| 113 test = test->prev(); |
| 114 } |
| 115 } |
| 116 delete[] arg_copy; |
| 117 } |
| 118 } |
| 119 if (print_run_count && tests_run != 1) |
| 120 printf("Ran %i tests.\n", tests_run); |
| 121 return 0; |
| 122 } |
OLD | NEW |