mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This configuration clause will suppress lex diagnostics and skip parsing
altogether if the code under the clause isn't active - the compiler must
have a repository version greater than or equal to the version given to
_compiler_version.
This option is only meant to be used sparingly and not to track the
Swift *language* version.
Example, if using a compiler versioned 700.0.28:
#if _compiler_version("700.0.23")
print("This code will compile for versions 700.0.23 and later.")
#else
This + code + will + not + be + parsed
#endif
Included are new diagnostics for checking that the version is formatted
correctly and isn't empty.
New tests:
- Compiler version comparison unit tests
- Build configuration diagnostics
- Skipping parsing of code under inactive clauses
rdar://problem/22730282
Swift SVN r32195
23 lines
727 B
C++
23 lines
727 B
C++
#include "swift/Basic/SourceLoc.h"
|
|
#include "swift/Basic/Version.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace swift;
|
|
using namespace llvm;
|
|
|
|
class CompilerVersionTest : public ::testing::Test {};
|
|
|
|
version::CompilerVersion CV(const char *VersionString) {
|
|
return version::CompilerVersion(VersionString, SourceLoc(), nullptr);
|
|
}
|
|
|
|
TEST_F(CompilerVersionTest, VersionComparison) {
|
|
EXPECT_GE(CV("700"), CV("602"));
|
|
EXPECT_GE(CV("700.0"), CV("700.1"));
|
|
EXPECT_GE(CV("700.0.1"), CV("700.1.0"));
|
|
EXPECT_GE(CV("700.8.23"), CV("700.0.21"));
|
|
EXPECT_GE(CV("700.0.1.1.0"), CV("700.0.1.1"));
|
|
EXPECT_GE(version::CompilerVersion(), version::CompilerVersion());
|
|
EXPECT_GE(version::CompilerVersion(), CV("999.999.999.999.999"));
|
|
}
|