|
| 1 | +//===--- Options.cpp ------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#include "swift/Option/Options.h" |
| 14 | +#include "llvm/Option/Option.h" |
| 15 | +#include "gtest/gtest.h" |
| 16 | + |
| 17 | +using namespace swift; |
| 18 | +using namespace swift::options; |
| 19 | + |
| 20 | +TEST(Options, outputPathCacheInvariant) { |
| 21 | + auto optTable = createSwiftOptTable(); |
| 22 | + // 0 is OP_INVALD |
| 23 | + for (auto id = 1; id < LastOption; ++id) { |
| 24 | + auto opt = optTable->getOption(id); |
| 25 | + // Only check the flag accepted by swift-frontend. |
| 26 | + if (!opt.hasFlag(SwiftFlags::FrontendOption)) |
| 27 | + continue; |
| 28 | + |
| 29 | + // The following two options are only accepted by migrator. |
| 30 | + if (id == OPT_emit_migrated_file_path || id == OPT_emit_remap_file_path) |
| 31 | + continue; |
| 32 | + |
| 33 | + auto name = opt.getName(); |
| 34 | + // Check that if a flag matches the convention `-emit-*-path{=}`, it should |
| 35 | + // be a path to an output file and should be marked as cache invariant. |
| 36 | + if (name.starts_with("emit") && |
| 37 | + (name.ends_with("-path") || name.ends_with("-path="))) |
| 38 | + ASSERT_TRUE(opt.hasFlag(SwiftFlags::CacheInvariant)); |
| 39 | + } |
| 40 | +} |
0 commit comments