Files
swift-mirror/test/Interop/Cxx/stdlib/use-std-string.swift
Egor Zhdan 2131d20fa9 [cxx-interop] Fix libstdc++ test failure with CentOS 7
CentOS 7 comes with an outdated libstdc++ version. In that version, `std::basic_string` has a `mutable` member, which makes all of `basic_string`'s member functions mutating in Swift. This prevents us from calling `size()` or `empty()` on an immutable value of `std.string`.

rdar://91548568
rdar://91670704
2022-04-14 12:47:18 +01:00

34 lines
843 B
Swift

// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
//
// REQUIRES: executable_test
//
// Enable this everywhere once we have a solution for modularizing other C++ stdlibs: rdar://87654514
// REQUIRES: OS=macosx || OS=linux-gnu
import StdlibUnittest
import StdString
#if os(Linux)
import std
// FIXME: import std.string once libstdc++ is split into submodules.
#else
import std.string
#endif
var StdStringTestSuite = TestSuite("StdString")
StdStringTestSuite.test("init") {
var s = CxxString() // declared as `var` because of outdated libstdc++ on CentOS 7
expectEqual(s.size(), 0)
expectTrue(s.empty())
}
StdStringTestSuite.test("push back") {
var s = CxxString()
s.push_back(42)
expectEqual(s.size(), 1)
expectFalse(s.empty())
expectEqual(s[0], 42)
}
runAllTests()