mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Fixes: https://bugs.swift.org/browse/SR-3455 https://bugs.swift.org/browse/SR-3663 https://bugs.swift.org/browse/SR-4032 https://bugs.swift.org/browse/SR-4031 Now, compilation conditions are validated at first, then evaluated. Also, in non-Swift3 mode, '&&' now has higher precedence than '||'. 'A || B && C || D' are evaluated as 'A || (B && C) || D'. Swift3 source breaking changes: * [SR-3663] This used to be accepted and evaluate to 'true' because of short circuit without any validation. #if true || true * 12 = try Anything is OK? print("foo") #endif In this change, remaining expressions are properly validated and diagnosed if it's invalid. * [SR-4031] Compound name references are now diagnosed as errors. e.g. `#if os(foo:bar:)(macOS)` or `#if FLAG(x:y:)` Swift3 compatibility: * [SR-3663] The precedence of '||' and '&&' are still the same and the following code evaluates to 'true'. #if false || true && false print("foo") #endif
55 lines
2.1 KiB
C++
55 lines
2.1 KiB
C++
#include "gtest/gtest.h"
|
|
#include "llvm/ADT/Optional.h"
|
|
#include "swift/Basic/SourceLoc.h"
|
|
#include "swift/Basic/Version.h"
|
|
|
|
using namespace swift;
|
|
using namespace llvm;
|
|
|
|
class CompilerVersionTest : public ::testing::Test {};
|
|
class VersionTest : public ::testing::Test{};
|
|
|
|
Optional<version::Version> CV(const char *VersionString) {
|
|
return version::Version::parseCompilerVersionString(VersionString,
|
|
SourceLoc(),
|
|
nullptr);
|
|
}
|
|
|
|
Optional<version::Version> V(const char *VersionString) {
|
|
return version::Version::parseVersionString(VersionString,
|
|
SourceLoc(),
|
|
nullptr);
|
|
}
|
|
|
|
TEST_F(CompilerVersionTest, VersionComparison) {
|
|
auto currentVersion = version::Version::getCurrentCompilerVersion();
|
|
EXPECT_GE(CV("700").getValue(), CV("602").getValue());
|
|
EXPECT_GE(CV("700.*").getValue(), CV("700.*").getValue());
|
|
EXPECT_GE(CV("700.*.1").getValue(), CV("700.*.0").getValue());
|
|
EXPECT_GE(CV("700.*.23").getValue(), CV("700.*.21").getValue());
|
|
EXPECT_GE(CV("700.*.1.1.0").getValue(), CV("700.*.1.1").getValue());
|
|
EXPECT_GE(currentVersion, currentVersion);
|
|
EXPECT_GE(currentVersion, CV("9223371.*.999.999.999").getValue());
|
|
}
|
|
|
|
TEST_F(VersionTest, VersionComparison) {
|
|
auto currentVersion = version::Version::getCurrentLanguageVersion();
|
|
EXPECT_GE(V("3").getValue(), V("2").getValue());
|
|
EXPECT_GE(V("2.0").getValue(), V("2.0").getValue());
|
|
EXPECT_GE(V("2.1").getValue(), V("2.0").getValue());
|
|
EXPECT_GE(V("3.1").getValue(), V("3.0.1").getValue());
|
|
EXPECT_GE(V("2.0").getValue(), V("2").getValue());
|
|
EXPECT_GE(currentVersion, currentVersion);
|
|
EXPECT_GE(currentVersion, V("1.0").getValue());
|
|
EXPECT_GE(currentVersion, V("2").getValue());
|
|
EXPECT_FALSE(V("2.n").hasValue());
|
|
EXPECT_FALSE(V("").hasValue());
|
|
EXPECT_FALSE(V("\"2.0\"").hasValue());
|
|
EXPECT_FALSE(V("2..").hasValue());
|
|
EXPECT_FALSE(V(".").hasValue());
|
|
EXPECT_FALSE(V("..").hasValue());
|
|
EXPECT_TRUE(V("1.").hasValue());
|
|
EXPECT_FALSE(V(".1").hasValue());
|
|
|
|
}
|