Christopher Wiley | 3616d13 | 2015-09-01 11:07:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015, The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 17 | #include "options.h" |
| 18 | |
Christopher Wiley | d93c5b7 | 2015-09-14 13:21:37 -0700 | [diff] [blame] | 19 | #include <iostream> |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 20 | #include <memory> |
Christopher Wiley | 3616d13 | 2015-09-01 11:07:48 -0700 | [diff] [blame] | 21 | #include <string> |
| 22 | #include <vector> |
| 23 | |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 24 | #include <gmock/gmock.h> |
Christopher Wiley | 3616d13 | 2015-09-01 11:07:48 -0700 | [diff] [blame] | 25 | #include <gtest/gtest.h> |
| 26 | |
Christopher Wiley | d93c5b7 | 2015-09-14 13:21:37 -0700 | [diff] [blame] | 27 | using std::cerr; |
| 28 | using std::endl; |
Christopher Wiley | 3616d13 | 2015-09-01 11:07:48 -0700 | [diff] [blame] | 29 | using std::string; |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 30 | using std::unique_ptr; |
| 31 | using std::vector; |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 32 | using testing::internal::CaptureStderr; |
| 33 | using testing::internal::GetCapturedStderr; |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 34 | |
| 35 | namespace android { |
| 36 | namespace aidl { |
| 37 | namespace { |
Christopher Wiley | 3616d13 | 2015-09-01 11:07:48 -0700 | [diff] [blame] | 38 | |
| 39 | const char kPreprocessCommandOutputFile[] = "output_file_name"; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 40 | const char kPreprocessCommandInput1[] = "input1.aidl"; |
| 41 | const char kPreprocessCommandInput2[] = "input2.aidl"; |
| 42 | const char kPreprocessCommandInput3[] = "input3.aidl"; |
Christopher Wiley | 3616d13 | 2015-09-01 11:07:48 -0700 | [diff] [blame] | 43 | const char* kPreprocessCommand[] = { |
| 44 | "aidl", "--preprocess", |
| 45 | kPreprocessCommandOutputFile, |
| 46 | kPreprocessCommandInput1, |
| 47 | kPreprocessCommandInput2, |
| 48 | kPreprocessCommandInput3, |
Christopher Wiley | d93c5b7 | 2015-09-14 13:21:37 -0700 | [diff] [blame] | 49 | nullptr, |
Christopher Wiley | 3616d13 | 2015-09-01 11:07:48 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
Christopher Wiley | 4432ccf | 2015-09-18 18:32:08 -0700 | [diff] [blame] | 52 | const char kCompileCommandInput[] = "directory/ITool.aidl"; |
Christopher Wiley | d93c5b7 | 2015-09-14 13:21:37 -0700 | [diff] [blame] | 53 | const char kCompileCommandIncludePath[] = "-Iinclude_path"; |
| 54 | const char* kCompileJavaCommand[] = { |
| 55 | "aidl", |
| 56 | "-b", |
| 57 | kCompileCommandIncludePath, |
| 58 | kCompileCommandInput, |
| 59 | nullptr, |
| 60 | }; |
Christopher Wiley | 4432ccf | 2015-09-18 18:32:08 -0700 | [diff] [blame] | 61 | const char kCompileCommandJavaOutput[] = "directory/ITool.java"; |
Christopher Wiley | d93c5b7 | 2015-09-14 13:21:37 -0700 | [diff] [blame] | 62 | |
Steven Moreland | b436cb7 | 2018-07-06 11:33:47 -0700 | [diff] [blame] | 63 | const char kCompileDepFileNinja[] = "--ninja"; |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 64 | const char* kCompileJavaCommandNinja[] = { |
| 65 | "aidl", |
| 66 | "-b", |
| 67 | kCompileDepFileNinja, |
| 68 | kCompileCommandIncludePath, |
| 69 | kCompileCommandInput, |
| 70 | nullptr, |
| 71 | }; |
| 72 | |
Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 73 | const char kCompileDepFile[] = "-doutput.deps"; |
Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 74 | const char kCompileCommandHeaderDir[] = "output/dir/"; |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 75 | const char kCompileCommandCppOutput[] = "some/file.cpp"; |
Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 76 | const char* kCompileCppCommand[] = { |
| 77 | "aidl-cpp", |
| 78 | kCompileCommandIncludePath, |
| 79 | kCompileDepFile, |
| 80 | kCompileCommandInput, |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 81 | kCompileCommandHeaderDir, |
| 82 | kCompileCommandCppOutput, |
Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 83 | nullptr, |
| 84 | }; |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 85 | const char* kCompileCppCommandNinja[] = { |
| 86 | "aidl-cpp", |
| 87 | kCompileCommandIncludePath, |
| 88 | kCompileDepFile, |
| 89 | kCompileDepFileNinja, |
| 90 | kCompileCommandInput, |
| 91 | kCompileCommandHeaderDir, |
| 92 | kCompileCommandCppOutput, |
| 93 | nullptr, |
| 94 | }; |
Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 95 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 96 | unique_ptr<Options> GetOptions(const char* command[], |
| 97 | Options::Language default_lang = Options::Language::JAVA) { |
Christopher Wiley | d93c5b7 | 2015-09-14 13:21:37 -0700 | [diff] [blame] | 98 | int argc = 0; |
| 99 | const char** command_part = command; |
| 100 | for (; *command_part; ++argc, ++command_part) {} |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 101 | unique_ptr<Options> ret(new Options(argc, command, default_lang)); |
| 102 | if (!ret->Ok()) { |
| 103 | cerr << ret->GetErrorMessage(); |
Christopher Wiley | d93c5b7 | 2015-09-14 13:21:37 -0700 | [diff] [blame] | 104 | cerr << "Failed to parse command line:"; |
| 105 | for (int i = 0; i < argc; ++i) { |
| 106 | cerr << " " << command[i]; |
| 107 | cerr << endl; |
| 108 | } |
| 109 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 110 | EXPECT_NE(ret, nullptr) << "Failed to parse options!"; |
| 111 | return ret; |
Christopher Wiley | d93c5b7 | 2015-09-14 13:21:37 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 114 | } // namespace |
| 115 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 116 | TEST(OptionsTests, ParsesPreprocess) { |
| 117 | unique_ptr<Options> options = GetOptions(kPreprocessCommand); |
| 118 | EXPECT_EQ(Options::Task::PREPROCESS, options->GetTask()); |
| 119 | EXPECT_EQ(false, options->FailOnParcelable()); |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 120 | EXPECT_EQ(0u, options->ImportDirs().size()); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 121 | EXPECT_EQ(0u, options->PreprocessedFiles().size()); |
| 122 | EXPECT_EQ(string{kPreprocessCommandOutputFile}, options->OutputFile()); |
| 123 | EXPECT_EQ(false, options->AutoDepFile()); |
Christopher Wiley | 3616d13 | 2015-09-01 11:07:48 -0700 | [diff] [blame] | 124 | const vector<string> expected_input{kPreprocessCommandInput1, |
| 125 | kPreprocessCommandInput2, |
| 126 | kPreprocessCommandInput3}; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 127 | EXPECT_EQ(expected_input, options->InputFiles()); |
Christopher Wiley | d93c5b7 | 2015-09-14 13:21:37 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 130 | TEST(OptionsTests, ParsesCompileJava) { |
| 131 | unique_ptr<Options> options = GetOptions(kCompileJavaCommand); |
| 132 | EXPECT_EQ(Options::Task::COMPILE, options->GetTask()); |
| 133 | EXPECT_EQ(Options::Language::JAVA, options->TargetLanguage()); |
| 134 | EXPECT_EQ(true, options->FailOnParcelable()); |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 135 | EXPECT_EQ(1u, options->ImportDirs().size()); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 136 | EXPECT_EQ(0u, options->PreprocessedFiles().size()); |
| 137 | EXPECT_EQ(string{kCompileCommandInput}, options->InputFiles().front()); |
| 138 | EXPECT_EQ(string{kCompileCommandJavaOutput}, options->OutputFile()); |
| 139 | EXPECT_EQ(false, options->AutoDepFile()); |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 140 | EXPECT_EQ(false, options->DependencyFileNinja()); |
| 141 | } |
| 142 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 143 | TEST(OptionsTests, ParsesCompileJavaNinja) { |
| 144 | unique_ptr<Options> options = GetOptions(kCompileJavaCommandNinja); |
| 145 | EXPECT_EQ(Options::Task::COMPILE, options->GetTask()); |
| 146 | EXPECT_EQ(Options::Language::JAVA, options->TargetLanguage()); |
| 147 | EXPECT_EQ(true, options->FailOnParcelable()); |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 148 | EXPECT_EQ(1u, options->ImportDirs().size()); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 149 | EXPECT_EQ(0u, options->PreprocessedFiles().size()); |
| 150 | EXPECT_EQ(string{kCompileCommandInput}, options->InputFiles().front()); |
| 151 | EXPECT_EQ(string{kCompileCommandJavaOutput}, options->OutputFile()); |
| 152 | EXPECT_EQ(false, options->AutoDepFile()); |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 153 | EXPECT_EQ(true, options->DependencyFileNinja()); |
Christopher Wiley | 3616d13 | 2015-09-01 11:07:48 -0700 | [diff] [blame] | 154 | } |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 155 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 156 | TEST(OptionsTests, ParsesCompileCpp) { |
| 157 | unique_ptr<Options> options = GetOptions(kCompileCppCommand, Options::Language::CPP); |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 158 | ASSERT_EQ(1u, options->ImportDirs().size()); |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 159 | EXPECT_EQ(string{kCompileCommandIncludePath}.substr(2), *options->ImportDirs().begin()); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 160 | EXPECT_EQ(string{kCompileDepFile}.substr(2), options->DependencyFile()); |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 161 | EXPECT_EQ(false, options->DependencyFileNinja()); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 162 | EXPECT_EQ(kCompileCommandInput, options->InputFiles().front()); |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 163 | EXPECT_EQ(kCompileCommandHeaderDir, options->OutputHeaderDir()); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 164 | EXPECT_EQ(kCompileCommandCppOutput, options->OutputFile()); |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 165 | } |
| 166 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 167 | TEST(OptionsTests, ParsesCompileCppNinja) { |
| 168 | unique_ptr<Options> options = GetOptions(kCompileCppCommandNinja, Options::Language::CPP); |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 169 | ASSERT_EQ(1u, options->ImportDirs().size()); |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 170 | EXPECT_EQ(string{kCompileCommandIncludePath}.substr(2), *options->ImportDirs().begin()); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 171 | EXPECT_EQ(string{kCompileDepFile}.substr(2), options->DependencyFile()); |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 172 | EXPECT_EQ(true, options->DependencyFileNinja()); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 173 | EXPECT_EQ(kCompileCommandInput, options->InputFiles().front()); |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 174 | EXPECT_EQ(kCompileCommandHeaderDir, options->OutputHeaderDir()); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 175 | EXPECT_EQ(kCompileCommandCppOutput, options->OutputFile()); |
Christopher Wiley | 4432ccf | 2015-09-18 18:32:08 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 178 | TEST(OptionsTests, ParsesCompileJavaMultiInput) { |
| 179 | const char* argv[] = { |
| 180 | "aidl", |
| 181 | "--lang=java", |
| 182 | kCompileCommandIncludePath, |
| 183 | "-o src_out", |
| 184 | "directory/input1.aidl", |
| 185 | "directory/input2.aidl", |
| 186 | "directory/input3.aidl", |
| 187 | nullptr, |
| 188 | }; |
| 189 | unique_ptr<Options> options = GetOptions(argv); |
| 190 | EXPECT_EQ(Options::Task::COMPILE, options->GetTask()); |
| 191 | EXPECT_EQ(Options::Language::JAVA, options->TargetLanguage()); |
| 192 | EXPECT_EQ(false, options->FailOnParcelable()); |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 193 | EXPECT_EQ(1u, options->ImportDirs().size()); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 194 | EXPECT_EQ(0u, options->PreprocessedFiles().size()); |
| 195 | const vector<string> expected_input{"directory/input1.aidl", "directory/input2.aidl", |
| 196 | "directory/input3.aidl"}; |
| 197 | EXPECT_EQ(expected_input, options->InputFiles()); |
| 198 | EXPECT_EQ(string{""}, options->OutputFile()); |
| 199 | EXPECT_EQ(false, options->AutoDepFile()); |
| 200 | EXPECT_EQ(false, options->DependencyFileNinja()); |
| 201 | EXPECT_EQ(string{""}, options->OutputHeaderDir()); |
Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 202 | EXPECT_EQ(string{"src_out/"}, options->OutputDir()); |
Christopher Wiley | 4432ccf | 2015-09-18 18:32:08 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 205 | TEST(OptionsTests, ParsesCompileRust) { |
| 206 | const char* argv[] = { |
| 207 | "aidl", "--lang=rust", kCompileCommandIncludePath, |
| 208 | "-o src_out", kCompileCommandInput, nullptr, |
| 209 | }; |
| 210 | unique_ptr<Options> options = GetOptions(argv); |
| 211 | EXPECT_EQ(Options::Task::COMPILE, options->GetTask()); |
| 212 | EXPECT_EQ(Options::Language::RUST, options->TargetLanguage()); |
| 213 | EXPECT_EQ(false, options->FailOnParcelable()); |
| 214 | EXPECT_EQ(1u, options->ImportDirs().size()); |
| 215 | EXPECT_EQ(0u, options->PreprocessedFiles().size()); |
| 216 | EXPECT_EQ(string{kCompileCommandInput}, options->InputFiles().front()); |
| 217 | EXPECT_EQ(string{""}, options->OutputFile()); |
| 218 | EXPECT_EQ(string{""}, options->OutputHeaderDir()); |
| 219 | EXPECT_EQ(string{"src_out/"}, options->OutputDir()); |
| 220 | EXPECT_EQ(false, options->AutoDepFile()); |
| 221 | EXPECT_EQ(false, options->DependencyFileNinja()); |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 224 | TEST(OptionsTests, ParsesCompileJavaInvalid_OutRequired) { |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 225 | // -o option is required |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 226 | string expected_error = "Output directory is not set. Set with --out."; |
| 227 | CaptureStderr(); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 228 | const char* arg_with_no_out_dir[] = { |
| 229 | "aidl", |
| 230 | "--lang=java", |
| 231 | kCompileCommandIncludePath, |
| 232 | "directory/input1.aidl", |
| 233 | "directory/input2.aidl", |
| 234 | "directory/input3.aidl", |
| 235 | nullptr, |
Christopher Wiley | 4432ccf | 2015-09-18 18:32:08 -0700 | [diff] [blame] | 236 | }; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 237 | EXPECT_EQ(false, GetOptions(arg_with_no_out_dir)->Ok()); |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 238 | EXPECT_THAT(GetCapturedStderr(), testing::HasSubstr(expected_error)); |
| 239 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 240 | |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 241 | TEST(OptionsTests, ParsesCompileJavaInvalid_RejectHeaderOut) { |
| 242 | string expected_error = "Header output directory is set, which does not make sense for Java."; |
| 243 | CaptureStderr(); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 244 | // -h options is not for Java |
| 245 | const char* arg_with_header_dir[] = { |
| 246 | "aidl", "--lang=java", kCompileCommandIncludePath, "-o src_out", |
| 247 | "-h header_out", "directory/input1.aidl", "directory/input2.aidl", "directory/input3.aidl", |
| 248 | nullptr, |
Christopher Wiley | 4432ccf | 2015-09-18 18:32:08 -0700 | [diff] [blame] | 249 | }; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 250 | EXPECT_EQ(false, GetOptions(arg_with_header_dir)->Ok()); |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 251 | EXPECT_THAT(GetCapturedStderr(), testing::HasSubstr(expected_error)); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | TEST(OptionsTests, ParsesCompileCppMultiInput) { |
| 255 | const char* argv[] = { |
| 256 | "aidl", |
| 257 | "--lang=cpp", |
| 258 | kCompileCommandIncludePath, |
| 259 | "-h header_out", |
| 260 | "-o src_out", |
| 261 | "directory/input1.aidl", |
| 262 | "directory/input2.aidl", |
| 263 | "directory/input3.aidl", |
| 264 | nullptr, |
| 265 | }; |
| 266 | unique_ptr<Options> options = GetOptions(argv); |
| 267 | EXPECT_EQ(Options::Task::COMPILE, options->GetTask()); |
| 268 | EXPECT_EQ(Options::Language::CPP, options->TargetLanguage()); |
| 269 | EXPECT_EQ(false, options->FailOnParcelable()); |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 270 | EXPECT_EQ(1u, options->ImportDirs().size()); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 271 | EXPECT_EQ(0u, options->PreprocessedFiles().size()); |
| 272 | const vector<string> expected_input{"directory/input1.aidl", "directory/input2.aidl", |
| 273 | "directory/input3.aidl"}; |
| 274 | EXPECT_EQ(expected_input, options->InputFiles()); |
| 275 | EXPECT_EQ(string{""}, options->OutputFile()); |
| 276 | EXPECT_EQ(false, options->AutoDepFile()); |
| 277 | EXPECT_EQ(false, options->DependencyFileNinja()); |
Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 278 | EXPECT_EQ(string{"header_out/"}, options->OutputHeaderDir()); |
| 279 | EXPECT_EQ(string{"src_out/"}, options->OutputDir()); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 280 | } |
| 281 | |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 282 | TEST(OptionsTests, ParsesCompileCppInvalid_OutRequired) { |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 283 | // -o option is required |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 284 | string expected_error = "Output directory is not set. Set with --out."; |
| 285 | CaptureStderr(); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 286 | const char* arg_with_no_out_dir[] = { |
| 287 | "aidl", |
| 288 | "--lang=cpp", |
| 289 | kCompileCommandIncludePath, |
| 290 | "directory/input1.aidl", |
| 291 | "directory/input2.aidl", |
| 292 | "directory/input3.aidl", |
| 293 | nullptr, |
| 294 | }; |
| 295 | EXPECT_EQ(false, GetOptions(arg_with_no_out_dir)->Ok()); |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 296 | EXPECT_THAT(GetCapturedStderr(), testing::HasSubstr(expected_error)); |
| 297 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 298 | |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 299 | TEST(OptionsTests, ParsesCompileCppInvalid_HeaderOutRequired) { |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 300 | // -h options is required as well |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 301 | string expected_error = "Header output directory is not set. Set with --header_out"; |
| 302 | CaptureStderr(); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 303 | const char* arg_with_no_header_dir[] = { |
| 304 | "aidl", |
| 305 | "--lang=cpp", |
| 306 | kCompileCommandIncludePath, |
| 307 | "-o src_out", |
| 308 | "directory/input1.aidl", |
| 309 | "directory/input2.aidl", |
| 310 | "directory/input3.aidl", |
| 311 | nullptr, |
| 312 | }; |
| 313 | EXPECT_EQ(false, GetOptions(arg_with_no_header_dir)->Ok()); |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 314 | EXPECT_THAT(GetCapturedStderr(), testing::HasSubstr(expected_error)); |
Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 317 | TEST(OptionsTests, ParsesCompileRustInvalid_OutRequired) { |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 318 | // -o option is required |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 319 | string expected_error = "Output directory is not set. Set with --out"; |
| 320 | CaptureStderr(); |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 321 | const char* arg_with_no_out_dir[] = { |
| 322 | "aidl", |
| 323 | "--lang=rust", |
| 324 | kCompileCommandIncludePath, |
| 325 | "directory/input1.aidl", |
| 326 | "directory/input2.aidl", |
| 327 | "directory/input3.aidl", |
| 328 | nullptr, |
| 329 | }; |
| 330 | EXPECT_EQ(false, GetOptions(arg_with_no_out_dir)->Ok()); |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 331 | EXPECT_THAT(GetCapturedStderr(), testing::HasSubstr(expected_error)); |
| 332 | } |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 333 | |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 334 | TEST(OptionsTests, ParsesCompileRustInvalid_RejectHeaderOut) { |
| 335 | string expected_error = "Header output directory is set, which does not make sense for Rust."; |
| 336 | CaptureStderr(); |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 337 | // -h options is not for Rust |
| 338 | const char* arg_with_header_dir[] = { |
| 339 | "aidl", "--lang=rust", kCompileCommandIncludePath, "-o src_out", |
| 340 | "-h header_out", "directory/input1.aidl", "directory/input2.aidl", "directory/input3.aidl", |
| 341 | nullptr, |
| 342 | }; |
| 343 | EXPECT_EQ(false, GetOptions(arg_with_header_dir)->Ok()); |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 344 | EXPECT_THAT(GetCapturedStderr(), testing::HasSubstr(expected_error)); |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 347 | } // namespace aidl |
Steven Moreland | f4c64df | 2019-07-29 19:54:04 -0700 | [diff] [blame] | 348 | } // namespace android |