6#include "flutter/third_party/re2/re2/re2.h"
8#include "gtest/gtest.h"
9#include "third_party/abseil-cpp/absl/status/statusor.h"
10#include "third_party/abseil-cpp/absl/strings/str_cat.h"
12namespace fs = std::filesystem;
18 temp_dir_base_ = fs::temp_directory_path(err);
23 if (should_delete_temp_dir_) {
24 fs::remove_all(temp_dir_);
29 static std::atomic<int32_t> count = 0;
31 ss <<
"LicenseCheckerTest_" << std::time(
nullptr) <<
"_"
32 << count.fetch_add(1);
33 temp_dir_ = temp_dir_base_ / ss.str();
35 fs::create_directory(temp_dir_, err);
37 should_delete_temp_dir_ =
true;
39 return absl::InternalError(
"can't make temp dir");
42 fs::path engine_path = temp_dir_ /
"engine";
43 fs::create_directory(engine_path, err);
45 return absl::InternalError(
"can't make temp engine dir");
52 fs::path temp_dir_base_;
54 bool should_delete_temp_dir_;
66const char* kUnknownHeader = R
"header(
73const char* kCHeader = R
"header(
82const char* kLicense = R
"lic(Test License
86const char* kUnknownLicense = R
"lic(Unknown License
91absl::StatusOr<Data> MakeTestData(
92 std::optional<std::string_view> include_filter_text = std::nullopt) {
93 std::stringstream include;
94 if (include_filter_text.has_value()) {
95 include << include_filter_text.value() << std::endl;
97 include <<
".*\\.cc" << std::endl;
99 absl::StatusOr<Filter> include_filter =
Filter::Open(include);
100 if (!include_filter.ok()) {
101 return include_filter.status();
103 std::stringstream exclude;
104 exclude <<
".*/ignore/.*" << std::endl;
105 absl::StatusOr<Filter> exclude_filter =
Filter::Open(exclude);
106 if (!exclude_filter.ok()) {
107 return exclude_filter.status();
110 absl::StatusOr<Catalog> catalog =
113 {"header",
"Copyright Test",
"(?:C )?Copyright Test"}});
115 return catalog.status();
120 .exclude_filter = std::move(*exclude_filter),
121 .catalog = std::move(catalog.value()),
122 .secondary_dir = fs::path(),
126absl::Status
WriteFile(std::string_view
data,
const fs::path& path) {
128 of.open(
path.string(), std::ios::binary);
130 return absl::InternalError(
"can't open file");
132 of.write(
data.data(),
data.length());
134 return absl::OkStatus();
137bool FindError(
const std::vector<absl::Status>& errors,
138 absl::StatusCode code,
139 std::string_view regex) {
140 return std::find_if(errors.begin(), errors.end(),
141 [code, regex](
const absl::Status& status) {
142 return status.code() == code &&
143 RE2::PartialMatch(status.message(), regex);
149 void Add(
const std::string& file) { files_.emplace_back(std::string(file)); }
151 absl::Status Commit() {
152 if (std::system(
"git init") != 0) {
153 return absl::InternalError(
"git init failed");
155 for (
const std::string& file : files_) {
156 if (std::system((
"git add " + file).c_str()) != 0) {
157 return absl::InternalError(
"git add failed: " + file);
160 if (std::system(
"git commit -m \"test\"") != 0) {
161 return absl::InternalError(
"git commit failed");
163 return absl::OkStatus();
167 std::vector<std::string> files_;
173 absl::StatusOr<fs::path> temp_path = MakeTempDir();
174 ASSERT_TRUE(temp_path.ok());
176 absl::StatusOr<Data>
data = MakeTestData();
177 ASSERT_TRUE(
data.ok());
179 fs::current_path(*temp_path);
180 ASSERT_TRUE(WriteFile(kHeader, *temp_path /
"main.cc").ok());
181 ASSERT_TRUE(WriteFile(kLicense, *temp_path /
"LICENSE").ok());
183 repo.Add(*temp_path /
"main.cc");
184 repo.Add(*temp_path /
"LICENSE");
185 ASSERT_TRUE(repo.Commit().ok());
187 std::stringstream ss;
188 std::vector<absl::Status> errors =
190 EXPECT_EQ(errors.size(), 0u) << errors[0];
194 absl::StatusOr<fs::path> temp_path = MakeTempDir();
195 ASSERT_TRUE(temp_path.ok());
197 absl::StatusOr<Data>
data = MakeTestData();
198 ASSERT_TRUE(
data.ok());
200 fs::current_path(*temp_path);
201 ASSERT_TRUE(WriteFile(kUnknownHeader, *temp_path /
"main.cc").ok());
203 repo.Add(*temp_path /
"main.cc");
204 ASSERT_TRUE(repo.Commit().ok());
206 std::stringstream ss;
207 std::vector<absl::Status> errors =
209 EXPECT_EQ(errors.size(), 1u);
210 EXPECT_TRUE(FindError(errors, absl::StatusCode::kNotFound,
211 "Expected copyright in.*main.cc"))
212 << (errors.size() > 0 ? absl::StrCat(errors[0]) :
"")
213 << (errors.size() > 1 ? absl::StrCat(
"\n", errors[1]) :
"");
217 absl::StatusOr<fs::path> temp_path = MakeTempDir();
218 ASSERT_TRUE(temp_path.ok());
220 absl::StatusOr<Data>
data = MakeTestData();
221 ASSERT_TRUE(
data.ok());
223 fs::current_path(*temp_path);
224 ASSERT_TRUE(WriteFile(kHeader, *temp_path /
"main.cc").ok());
226 ASSERT_TRUE(WriteFile(kHeader, *temp_path /
"foo.cc").ok());
227 ASSERT_TRUE(WriteFile(kUnknownLicense, *temp_path /
"LICENSE").ok());
229 repo.Add(*temp_path /
"main.cc");
230 repo.Add(*temp_path /
"foo.cc");
231 repo.Add(*temp_path /
"LICENSE");
232 ASSERT_TRUE(repo.Commit().ok());
234 std::stringstream ss;
235 std::vector<absl::Status> errors =
237 EXPECT_EQ(errors.size(), 1u);
238 ASSERT_TRUE(!errors.empty());
239 EXPECT_TRUE(FindError(errors, absl::StatusCode::kNotFound,
240 "Unknown license in.*LICENSE"))
245 absl::StatusOr<fs::path> temp_path = MakeTempDir();
246 ASSERT_TRUE(temp_path.ok());
248 absl::StatusOr<Data>
data = MakeTestData();
249 ASSERT_TRUE(
data.ok());
251 fs::current_path(*temp_path);
252 ASSERT_EQ(std::system(
"echo \"Hello world!\" > main.cc"), 0);
254 repo.Add(*temp_path /
"main.cc");
255 ASSERT_TRUE(repo.Commit().ok());
257 std::stringstream ss;
258 std::vector<absl::Status> errors =
260 EXPECT_EQ(errors.size(), 1u);
261 EXPECT_TRUE(FindError(errors, absl::StatusCode::kNotFound,
262 "Expected copyright in.*main.cc"))
263 << (errors.size() > 0 ? absl::StrCat(errors[0]) :
"");
267 absl::StatusOr<fs::path> temp_path = MakeTempDir();
268 ASSERT_TRUE(temp_path.ok());
270 absl::StatusOr<Data>
data = MakeTestData();
271 ASSERT_TRUE(
data.ok());
273 std::stringstream exclude;
274 exclude << R
"regex(^main\.cc)regex" << std::endl;
275 absl::StatusOr<Filter> exclude_filter = Filter::Open(exclude);
276 ASSERT_TRUE(exclude_filter.ok());
277 data->exclude_filter = std::move(exclude_filter.value());
279 fs::current_path(*temp_path);
280 ASSERT_TRUE(WriteFile(kUnknownHeader, *temp_path / "main.cc").ok());
282 repo.Add(*temp_path /
"main.cc");
283 ASSERT_TRUE(repo.Commit().ok());
285 std::stringstream ss;
286 std::vector<absl::Status> errors =
288 EXPECT_EQ(errors.size(), 0u);
292 absl::StatusOr<fs::path> temp_path = MakeTempDir();
293 ASSERT_TRUE(temp_path.ok());
295 absl::StatusOr<Data>
data = MakeTestData();
296 ASSERT_TRUE(
data.ok());
298 std::stringstream exclude;
299 exclude <<
"^LICENSE" << std::endl;
300 absl::StatusOr<Filter> exclude_filter =
Filter::Open(exclude);
301 ASSERT_TRUE(exclude_filter.ok());
302 data->exclude_filter = std::move(exclude_filter.value());
304 fs::current_path(*temp_path);
305 ASSERT_TRUE(WriteFile(kHeader, *temp_path /
"main.cc").ok());
306 ASSERT_TRUE(WriteFile(kLicense, *temp_path /
"LICENSE").ok());
308 repo.Add(*temp_path /
"main.cc");
309 repo.Add(*temp_path /
"LICENSE");
310 ASSERT_TRUE(repo.Commit().ok());
312 std::stringstream ss;
313 std::vector<absl::Status> errors =
315 EXPECT_EQ(errors.size(), 0u) << errors[0];
317 EXPECT_EQ(ss.str(), R
"output(engine
324 absl::StatusOr<fs::path> temp_path = MakeTempDir();
325 ASSERT_TRUE(temp_path.ok());
327 absl::StatusOr<Data> data = MakeTestData();
328 ASSERT_TRUE(data.ok());
330 fs::current_path(*temp_path);
331 ASSERT_TRUE(WriteFile(kHeader, *temp_path / "main.cc").ok());
333 repo.Add(*temp_path /
"main.cc");
334 ASSERT_TRUE(repo.Commit().ok());
336 std::stringstream ss;
337 std::vector<absl::Status> errors =
339 EXPECT_EQ(errors.size(), 0u) << errors[0];
341 EXPECT_EQ(ss.str(), R
"output(engine
348 absl::StatusOr<fs::path> temp_path = MakeTempDir();
349 ASSERT_TRUE(temp_path.ok());
351 absl::StatusOr<Data> data = MakeTestData();
352 ASSERT_TRUE(data.ok());
354 fs::current_path(*temp_path);
355 ASSERT_TRUE(WriteFile(kHeader, *temp_path / "main.cc").ok());
356 ASSERT_TRUE(WriteFile(kCHeader, *temp_path /
"cmain.cc").ok());
359 repo.Add(
"cmain.cc");
360 ASSERT_TRUE(repo.Commit().ok());
362 std::stringstream ss;
363 std::vector<absl::Status> errors =
365 EXPECT_EQ(errors.size(), 0u);
367 EXPECT_EQ(ss.str(), R
"output(engine
370--------------------------------------------------------------------------------
378 absl::StatusOr<fs::path> temp_path = MakeTempDir();
379 ASSERT_TRUE(temp_path.ok());
381 absl::StatusOr<Data> data = MakeTestData();
382 ASSERT_TRUE(data.ok());
384 fs::current_path(*temp_path);
385 ASSERT_TRUE(WriteFile(kHeader, *temp_path / "a.cc").ok());
386 ASSERT_TRUE(WriteFile(kHeader, *temp_path /
"b.cc").ok());
390 ASSERT_TRUE(repo.Commit().ok());
392 std::stringstream ss;
393 std::vector<absl::Status> errors =
395 EXPECT_EQ(errors.size(), 0u);
397 EXPECT_EQ(ss.str(), R
"output(engine
404 absl::StatusOr<fs::path> temp_path = MakeTempDir();
405 ASSERT_TRUE(temp_path.ok());
407 absl::StatusOr<Data> data = MakeTestData();
408 ASSERT_TRUE(data.ok());
410 fs::current_path(*temp_path);
411 ASSERT_EQ(std::system("mkdir -p third_party/foobar"), 0);
412 ASSERT_TRUE(WriteFile(kHeader, *temp_path /
"a.cc").ok());
414 WriteFile(kHeader, *temp_path /
"third_party" /
"foobar" /
"b.cc").ok());
417 repo.Add(
"third_party/foobar/b.cc");
418 ASSERT_TRUE(repo.Commit().ok());
420 std::stringstream ss;
421 std::vector<absl::Status> errors =
423 EXPECT_EQ(errors.size(), 0u);
425 EXPECT_EQ(ss.str(), R
"output(engine
433 absl::StatusOr<fs::path> temp_path = MakeTempDir();
434 ASSERT_TRUE(temp_path.ok());
436 absl::StatusOr<Data> data = MakeTestData();
437 ASSERT_TRUE(data.ok());
439 fs::current_path(*temp_path);
440 ASSERT_TRUE(WriteFile(kHeader, *temp_path / "main.cc").ok());
441 ASSERT_TRUE(WriteFile(kLicense, *temp_path /
"LICENSE").ok());
445 ASSERT_TRUE(repo.Commit().ok());
447 std::stringstream ss;
448 std::vector<absl::Status> errors =
450 EXPECT_EQ(errors.size(), 0u);
452 EXPECT_EQ(ss.str(), R
"output(engine
455--------------------------------------------------------------------------------
464 absl::StatusOr<fs::path> temp_path = MakeTempDir();
465 ASSERT_TRUE(temp_path.ok());
467 absl::StatusOr<Data> data = MakeTestData();
468 ASSERT_TRUE(data.ok());
470 fs::current_path(*temp_path);
471 ASSERT_EQ(std::system("echo \"Hello world!\" > main.cc"), 0);
472 ASSERT_TRUE(WriteFile(kLicense, *temp_path /
"LICENSE").ok());
476 ASSERT_TRUE(repo.Commit().ok());
478 std::stringstream ss;
479 std::vector<absl::Status> errors =
481 EXPECT_EQ(errors.size(), 1u);
483 EXPECT_TRUE(FindError(errors, absl::StatusCode::kNotFound,
484 "Expected root copyright in.*main.cc"))
485 << (errors.size() > 0 ? absl::StrCat(errors[0]) :
"");
489 absl::StatusOr<fs::path> temp_path = MakeTempDir();
490 ASSERT_TRUE(temp_path.ok());
492 absl::StatusOr<Data>
data = MakeTestData();
493 ASSERT_TRUE(
data.ok());
495 fs::current_path(*temp_path);
496 ASSERT_EQ(std::system(
"mkdir -p third_party/foobar"), 0);
497 ASSERT_EQ(std::system(
"echo \"Hello world!\" > third_party/foobar/foo.cc"),
499 ASSERT_TRUE(WriteFile(kLicense, *temp_path /
"LICENSE").ok());
501 WriteFile(kLicense, *temp_path /
"third_party" /
"foobar" /
"LICENSE")
505 repo.Add(
"third_party/foobar/foo.cc");
506 repo.Add(
"third_party/foobar/LICENSE");
507 ASSERT_TRUE(repo.Commit().ok());
509 std::stringstream ss;
510 std::vector<absl::Status> errors =
512 EXPECT_EQ(errors.size(), 0u);
514 EXPECT_EQ(ss.str(), R
"output(foobar
522 absl::StatusOr<fs::path> temp_path = MakeTempDir();
523 ASSERT_TRUE(temp_path.ok());
525 absl::StatusOr<Data> data = MakeTestData();
526 ASSERT_TRUE(data.ok());
528 fs::current_path(*temp_path);
529 ASSERT_TRUE(WriteFile(kHeader, *temp_path / "main.cc").ok());
530 ASSERT_TRUE(WriteFile(absl::StrCat(kLicense,
"\n----------------------\n"),
531 *temp_path /
"LICENSE")
534 repo.Add(*temp_path /
"main.cc");
535 repo.Add(*temp_path /
"LICENSE");
536 ASSERT_TRUE(repo.Commit().ok());
538 std::stringstream ss;
539 std::vector<absl::Status> errors =
541 EXPECT_EQ(errors.size(), 0u) << errors[0];
543 EXPECT_EQ(ss.str(), R
"output(engine
546--------------------------------------------------------------------------------
555 absl::StatusOr<fs::path> temp_path = MakeTempDir();
556 ASSERT_TRUE(temp_path.ok());
558 absl::StatusOr<Data> data = MakeTestData();
559 ASSERT_TRUE(data.ok());
561 fs::current_path(*temp_path);
562 ASSERT_TRUE(WriteFile(R"header(
571 *temp_path / "main.cc")
574 repo.Add(*temp_path /
"main.cc");
575 ASSERT_TRUE(repo.Commit().ok());
577 std::stringstream ss;
578 std::vector<absl::Status> errors =
580 EXPECT_EQ(errors.size(), 0u) << errors[0];
582 EXPECT_EQ(ss.str(), R
"output(engine
589 absl::StatusOr<fs::path> temp_path = MakeTempDir();
590 ASSERT_TRUE(temp_path.ok());
592 absl::StatusOr<Data> data = MakeTestData();
593 ASSERT_TRUE(data.ok());
595 fs::current_path(*temp_path);
596 ASSERT_EQ(std::system("mkdir -p third_party/foobar"), 0);
598 WriteFile(kUnknownHeader, *temp_path /
"third_party/foobar/foo.cc").ok());
600 WriteFile(kLicense, *temp_path /
"third_party" /
"foobar" /
"LICENSE")
603 repo.Add(
"third_party/foobar/foo.cc");
604 repo.Add(
"third_party/foobar/LICENSE");
605 ASSERT_TRUE(repo.Commit().ok());
608 std::stringstream ss;
609 std::vector<absl::Status> errors =
612 EXPECT_EQ(errors.size(), 1u);
614 FindError(errors, absl::StatusCode::kNotFound,
615 "(?s).*foo.cc.*Selector didn't match.*Unknown Copyright"))
616 << (errors.size() > 0 ? absl::StrCat(errors[0]) :
"");
620 absl::StatusOr<fs::path> temp_path = MakeTempDir();
621 ASSERT_TRUE(temp_path.ok());
623 absl::StatusOr<Data>
data = MakeTestData(
"NOTICES");
624 ASSERT_TRUE(
data.ok());
626 std::string notices = R
"notices(engine
630--------------------------------------------------------------------------------
637 fs::current_path(*temp_path);
638 ASSERT_TRUE(WriteFile(notices, "NOTICES").ok());
641 ASSERT_TRUE(repo.Commit().ok());
643 std::stringstream ss;
644 std::vector<absl::Status> errors =
646 EXPECT_EQ(errors.size(), 0u) << errors[0];
648 EXPECT_EQ(ss.str(), notices);
652 absl::StatusOr<fs::path> temp_path = MakeTempDir();
653 ASSERT_TRUE(temp_path.ok());
655 absl::StatusOr<Data>
data = MakeTestData(
"NOTICES");
656 ASSERT_TRUE(
data.ok());
658 std::string notices = R
"notices(engine
662--------------------------------------------------------------------------------
668 fs::current_path(*temp_path);
669 ASSERT_TRUE(WriteFile(notices, "NOTICES").ok());
672 ASSERT_TRUE(repo.Commit().ok());
674 std::stringstream ss;
676 std::vector<absl::Status> errors =
678 EXPECT_EQ(errors.size(), 1u);
679 ASSERT_TRUE(!errors.empty());
680 EXPECT_TRUE(FindError(errors, absl::StatusCode::kNotFound,
"NOTICES"))
685 absl::StatusOr<fs::path> temp_path = MakeTempDir();
686 ASSERT_TRUE(temp_path.ok());
688 absl::StatusOr<Data>
data = MakeTestData();
689 ASSERT_TRUE(
data.ok());
691 fs::current_path(*temp_path);
693 const char* deps_file = R
"deps(
695 'child/third_party/foobar': {
697 'packages': [{'package': 'flutter/testing/foobar', 'version': '1.0.0'}],
701 ASSERT_TRUE(WriteFile(deps_file, "DEPS").ok());
703 fs::create_directories(
"child/third_party/foobar");
704 ASSERT_TRUE(WriteFile(kHeader,
"child/third_party/foobar/foobar.cc").ok());
708 ASSERT_TRUE(repo.Commit().ok());
710 fs::current_path(*temp_path /
"child");
711 std::stringstream ss;
713 EXPECT_EQ(errors.size(), 0u) << (errors.empty() ?
"" : errors[0].message());
715 EXPECT_EQ(ss.str(), R
"output(foobar
722 absl::StatusOr<fs::path> temp_path = MakeTempDir();
723 ASSERT_TRUE(temp_path.ok());
725 absl::StatusOr<Data> data = MakeTestData();
726 ASSERT_TRUE(data.ok());
728 fs::current_path(*temp_path);
730 const char* deps_file = R
"deps(
732 'third_party/foobar': {
734 'packages': [{'package': 'flutter/testing/foobar', 'version': '1.0.0'}],
738 ASSERT_TRUE(WriteFile(deps_file, "DEPS").ok());
740 fs::create_directories(
"third_party/foobar");
741 ASSERT_TRUE(WriteFile(kHeader,
"third_party/foobar/foobar.cc").ok());
745 ASSERT_TRUE(repo.Commit().ok());
747 std::stringstream ss;
748 std::vector<absl::Status> errors =
750 EXPECT_EQ(errors.size(), 0u) << (errors.empty() ?
"" : errors[0].message());
752 EXPECT_EQ(ss.str(), R
"output(foobar
759 absl::StatusOr<fs::path> temp_path = MakeTempDir();
760 ASSERT_TRUE(temp_path.ok());
762 absl::StatusOr<Data> data = MakeTestData();
763 ASSERT_TRUE(data.ok());
765 fs::current_path(*temp_path);
766 fs::create_directories("engine/third_party/foobar");
767 fs::create_directories(
"secondary/third_party/foobar");
768 ASSERT_TRUE(WriteFile(kHeader,
"engine/third_party/foobar/foobar.cc").ok());
770 WriteFile(kLicense,
"secondary/third_party/foobar/license.txt").ok());
772 data->secondary_dir = *temp_path /
"secondary";
774 fs::current_path(*temp_path /
"engine");
776 repo.Add(
"third_party/foobar/foobar.cc");
777 ASSERT_TRUE(repo.Commit().ok());
779 std::stringstream ss;
780 std::vector<absl::Status> errors =
782 EXPECT_EQ(errors.size(), 0u) << errors[0];
784 EXPECT_EQ(ss.str(), R
"notices(foobar
787--------------------------------------------------------------------------------
797 absl::StatusOr<fs::path> temp_path = MakeTempDir();
798 ASSERT_TRUE(temp_path.ok());
800 absl::StatusOr<Data> data = MakeTestData();
801 ASSERT_TRUE(data.ok());
803 fs::current_path(*temp_path);
804 ASSERT_TRUE(WriteFile(kHeader, *temp_path / "main.cc").ok());
805 ASSERT_TRUE(WriteFile(kLicense, *temp_path /
"LICENSE").ok());
809 ASSERT_TRUE(repo.Commit().ok());
811 std::stringstream ss;
812 std::string working_dir = temp_path->string() +
"/";
813 std::vector<absl::Status> errors =
815 EXPECT_EQ(errors.size(), 0u) << (errors.empty() ?
"" : errors[0].message());
817 EXPECT_EQ(ss.str(), R
"output(engine
820--------------------------------------------------------------------------------
829 absl::StatusOr<fs::path> temp_path = MakeTempDir();
830 ASSERT_TRUE(temp_path.ok());
832 absl::StatusOr<Data> data = MakeTestData(".*txt");
833 ASSERT_TRUE(
data.ok());
835 fs::current_path(*temp_path);
837 ASSERT_TRUE(WriteFile(R
"lic(Test License
840 *temp_path / "foobar.txt")
843 repo.Add(
"foobar.txt");
844 ASSERT_TRUE(repo.Commit().ok());
846 std::stringstream ss;
847 std::vector<absl::Status> errors =
849 EXPECT_EQ(errors.size(), 0u) << errors[0];
851 EXPECT_EQ(ss.str(), R
"output(engine
859 absl::StatusOr<fs::path> temp_path = MakeTempDir();
860 ASSERT_TRUE(temp_path.ok());
862 absl::StatusOr<Data> data = MakeTestData();
863 ASSERT_TRUE(data.ok());
865 fs::current_path(*temp_path);
866 fs::create_directories("third_party/vulkan-deps");
867 fs::create_directories(
"third_party/vulkan-deps/foobar");
870 WriteFile(kLicense, *temp_path /
"third_party/vulkan-deps/foobar/LICENSE")
872 ASSERT_TRUE(WriteFile(kHeader,
873 *temp_path /
"third_party/vulkan-deps/foobar/foobar.cc")
877 repo.Add(*temp_path /
"third_party/vulkan-deps/foobar/LICENSE");
878 repo.Add(*temp_path /
"third_party/vulkan-deps/foobar/foobar.cc");
879 ASSERT_TRUE(repo.Commit().ok());
881 std::stringstream ss;
882 std::vector<absl::Status> errors =
884 EXPECT_EQ(errors.size(), 0u) << errors[0];
886 EXPECT_EQ(ss.str(), R
"output(foobar
889--------------------------------------------------------------------------------
898 absl::StatusOr<fs::path> temp_path = MakeTempDir();
899 ASSERT_TRUE(temp_path.ok());
901 absl::StatusOr<Data> data = MakeTestData();
902 ASSERT_TRUE(data.ok());
904 fs::current_path(*temp_path);
905 fs::create_directories("third_party/vulkan-deps");
906 fs::create_directories(
"third_party/vulkan-deps/foobar");
909 WriteFile(kLicense, *temp_path /
"third_party/vulkan-deps/LICENSE").ok());
911 WriteFile(kHeader, *temp_path /
"third_party/vulkan-deps/foobar.cc")
915 repo.Add(*temp_path /
"third_party/vulkan-deps/LICENSE");
916 repo.Add(*temp_path /
"third_party/vulkan-deps/foobar.cc");
917 ASSERT_TRUE(repo.Commit().ok());
919 std::stringstream ss;
920 std::vector<absl::Status> errors =
922 EXPECT_EQ(errors.size(), 0u) << errors[0];
924 EXPECT_EQ(ss.str(), R
"output(vulkan-deps
927--------------------------------------------------------------------------------
936 absl::StatusOr<fs::path> temp_path = MakeTempDir();
937 ASSERT_TRUE(temp_path.ok());
939 absl::StatusOr<Data> data =
940 MakeTestData(".*/COPYING|.*cc");
941 ASSERT_TRUE(
data.ok());
943 fs::current_path(*temp_path);
944 fs::create_directories(
"third_party/foobar");
946 ASSERT_TRUE(WriteFile(R
"lic(Test License
949 *temp_path / "third_party/foobar/LICENSE")
951 ASSERT_TRUE(WriteFile(R
"lic(Test License
954 *temp_path / "third_party/foobar/COPYING")
956 ASSERT_TRUE(WriteFile(kHeader,
"third_party/foobar/foobar.cc").ok());
958 repo.Add(
"third_party/foobar/COPYING");
959 repo.Add(
"third_party/foobar/LICENSE");
960 repo.Add(
"third_party/foobar/foobar.cc");
961 ASSERT_TRUE(repo.Commit().ok());
963 std::stringstream ss;
964 std::vector<absl::Status> errors =
966 EXPECT_EQ(errors.size(), 0u) << errors[0];
968 EXPECT_EQ(ss.str(), R
"output(foobar
971--------------------------------------------------------------------------------
976--------------------------------------------------------------------------------
985 absl::StatusOr<fs::path> temp_path = MakeTempDir();
986 ASSERT_TRUE(temp_path.ok());
988 absl::StatusOr<Data> data = MakeTestData();
989 ASSERT_TRUE(data.ok());
991 fs::current_path(*temp_path);
992 ASSERT_TRUE(WriteFile(kHeader, *temp_path / "main.cc").ok());
994 repo.Add(*temp_path /
"main.cc");
995 ASSERT_TRUE(repo.Commit().ok());
998 std::stringstream ss;
999 std::vector<absl::Status> errors =
1001 EXPECT_EQ(errors.size(), 0u) << errors[0];
1003 EXPECT_EQ(ss.str(), R
"output(testroot
static absl::StatusOr< Catalog > Make(const std::vector< Entry > &entries)
Make a Catalog for testing.
static absl::StatusOr< Filter > Open(std::string_view path)
static std::vector< absl::Status > Run(std::string_view working_dir, std::ostream &licenses, const Data &data)
absl::StatusOr< fs::path > MakeTempDir()
TEST_F(LicenseCheckerTest, SimplePass)
bool WriteFile(const std::string &path, const char *data, ssize_t size)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
bool treat_unmatched_comments_as_errors
std::optional< std::string > root_package_name
std::shared_ptr< const fml::Mapping > data