Skip to content

[nfc][cxx-interop] Add a basic test for using std::string. #41166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion test/Interop/Cxx/stdlib/Inputs/module.modulemap
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module StdVector {
header "std-vector.h"
}
requires cplusplus
}

module StdString {
header "std-string.h"
requires cplusplus
}
8 changes: 8 additions & 0 deletions test/Interop/Cxx/stdlib/Inputs/std-string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef TEST_INTEROP_CXX_STDLIB_INPUTS_STD_STRING_H
#define TEST_INTEROP_CXX_STDLIB_INPUTS_STD_STRING_H

#include <string>

using CxxString = std::string;

#endif // TEST_INTEROP_CXX_STDLIB_INPUTS_STD_STRING_H
29 changes: 29 additions & 0 deletions test/Interop/Cxx/stdlib/use-std-string.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-cxx-interop)
//
// REQUIRES: executable_test
//
// Enable this everywhere once we have a solution for modularizing libstdc++: rdar://87654514
// REQUIRES: OS=macosx

import StdlibUnittest
import StdString
import std.string

var StdStringTestSuite = TestSuite("StdString")

StdStringTestSuite.test("init") {
let s = CxxString()
expectEqual(s.size(), 0)
expectTrue(s.empty())
}

// LLVM module verification fails for calls to std::string::push_back: rdar://88343327
// StdStringTestSuite.test("push back") {
// var s = CxxString()
// s.push_back(42)
// expectEqual(s.size(), 1)
// expectFalse(s.empty())
// expectEqual(s[0], 42)
// }

runAllTests()