OLD | NEW |
---|---|
1 // Copyright 2008 Google Inc. All Rights Reserved. | 1 // Copyright 2008 Google Inc. 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 17 matching lines...) Expand all Loading... | |
28 #include <v8.h> | 28 #include <v8.h> |
29 #include <cstdlib> | 29 #include <cstdlib> |
30 #include <cstring> | 30 #include <cstring> |
31 #include <cstdio> | 31 #include <cstdio> |
32 #include "cctest.h" | 32 #include "cctest.h" |
33 | 33 |
34 | 34 |
35 CcTest* CcTest::last_ = NULL; | 35 CcTest* CcTest::last_ = NULL; |
36 | 36 |
37 | 37 |
38 CcTest::CcTest(TestFunction* callback, const char* file, const char* name) | 38 CcTest::CcTest(TestFunction* callback, const char* file, const char* name, |
39 : callback_(callback), name_(name), prev_(last_) { | 39 bool enabled) : callback_(callback), name_(name), prev_(last_) { |
iposva
2008/09/05 00:00:04
Not sure this is the proper style for wrapping par
| |
40 // Find the base name of this test (const_cast required on Windows). | 40 // Find the base name of this test (const_cast required on Windows). |
41 char *basename = strrchr(const_cast<char *>(file), '/'); | 41 char *basename = strrchr(const_cast<char *>(file), '/'); |
42 if (!basename) { | 42 if (!basename) { |
43 basename = strrchr(const_cast<char *>(file), '\\'); | 43 basename = strrchr(const_cast<char *>(file), '\\'); |
44 } | 44 } |
45 if (!basename) { | 45 if (!basename) { |
46 basename = strdup(file); | 46 basename = strdup(file); |
47 } else { | 47 } else { |
48 basename = strdup(basename + 1); | 48 basename = strdup(basename + 1); |
49 } | 49 } |
50 // Drop the extension, if there is one. | 50 // Drop the extension, if there is one. |
51 char *extension = strrchr(basename, '.'); | 51 char *extension = strrchr(basename, '.'); |
52 if (extension) *extension = 0; | 52 if (extension) *extension = 0; |
53 // Install this test in the list of tests | 53 // Install this test in the list of tests |
54 file_ = basename; | 54 file_ = basename; |
55 enabled_ = enabled; | |
55 prev_ = last_; | 56 prev_ = last_; |
56 last_ = this; | 57 last_ = this; |
57 } | 58 } |
58 | 59 |
59 | 60 |
60 static void PrintTestList(CcTest* current) { | 61 static void PrintTestList(CcTest* current) { |
61 if (current == NULL) return; | 62 if (current == NULL) return; |
62 PrintTestList(current->prev()); | 63 PrintTestList(current->prev()); |
63 printf("%s/%s\n", current->file(), current->name()); | 64 printf("%s/%s\n", current->file(), current->name()); |
64 } | 65 } |
65 | 66 |
66 | 67 |
67 static int RunMatchingTests(CcTest* current, char* file_or_name) { | |
68 if (current == NULL) return 0; | |
69 int run_count = 0; | |
70 if (strcmp(current->file(), file_or_name) == 0 | |
71 || strcmp(current->name(), file_or_name) == 0) { | |
72 current->Run(); | |
73 run_count++; | |
74 } | |
75 return run_count + RunMatchingTests(current->prev(), file_or_name); | |
76 } | |
77 | |
78 | |
79 static int RunMatchingTests(CcTest* current, char* file, char* name) { | |
80 if (current == NULL) return 0; | |
81 int run_count = 0; | |
82 if (strcmp(current->file(), file) == 0 | |
83 && strcmp(current->name(), name) == 0) { | |
84 current->Run(); | |
85 run_count++; | |
86 } | |
87 return run_count + RunMatchingTests(current->prev(), file, name); | |
88 } | |
89 | |
90 | |
91 int main(int argc, char* argv[]) { | 68 int main(int argc, char* argv[]) { |
92 v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true); | 69 v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true); |
93 int tests_run = 0; | 70 int tests_run = 0; |
94 bool print_run_count = true; | 71 bool print_run_count = true; |
95 for (int i = 1; i < argc; i++) { | 72 for (int i = 1; i < argc; i++) { |
96 char* arg = argv[i]; | 73 char* arg = argv[i]; |
97 if (strcmp(arg, "--list") == 0) { | 74 if (strcmp(arg, "--list") == 0) { |
98 PrintTestList(CcTest::last()); | 75 PrintTestList(CcTest::last()); |
99 print_run_count = false; | 76 print_run_count = false; |
77 | |
100 } else { | 78 } else { |
101 char* arg_copy = strdup(arg); | 79 char* arg_copy = strdup(arg); |
102 char* testname = strchr(arg_copy, '/'); | 80 char* testname = strchr(arg_copy, '/'); |
103 if (testname) { | 81 if (testname) { |
104 // Split the string in two by nulling the slash and then run | 82 // Split the string in two by nulling the slash and then run |
105 // exact matches. | 83 // exact matches. |
106 *testname = 0; | 84 *testname = 0; |
107 tests_run += RunMatchingTests(CcTest::last(), arg_copy, testname + 1); | 85 char* file = arg_copy; |
86 char* name = testname + 1; | |
87 CcTest* test = CcTest::last(); | |
88 while (test != NULL) { | |
89 if (test->enabled() | |
90 && strcmp(test->file(), file) == 0 | |
91 && strcmp(test->name(), name) == 0) { | |
92 test->Run(); | |
93 tests_run++; | |
94 } | |
95 test = test->prev(); | |
96 } | |
97 | |
108 } else { | 98 } else { |
109 // Run all tests with the specified file or test name. | 99 // Run all tests with the specified file or test name. |
110 tests_run += RunMatchingTests(CcTest::last(), arg_copy); | 100 char* file_or_name = arg_copy; |
101 CcTest* test = CcTest::last(); | |
102 while (test != NULL) { | |
103 if (test->enabled() | |
104 && (strcmp(test->file(), file_or_name) == 0 | |
105 || strcmp(test->name(), file_or_name) == 0)) { | |
106 test->Run(); | |
107 tests_run++; | |
108 } | |
109 test = test->prev(); | |
110 } | |
111 } | 111 } |
112 free(arg_copy); | 112 free(arg_copy); |
113 } | 113 } |
114 } | 114 } |
115 if (print_run_count && tests_run != 1) | 115 if (print_run_count && tests_run != 1) |
116 printf("Ran %i tests.\n", tests_run); | 116 printf("Ran %i tests.\n", tests_run); |
117 return 0; | 117 return 0; |
118 } | 118 } |
OLD | NEW |