Skip to content

Commit ae454bb

Browse files
authored
Test C++ structs as parameters and return types as declarations and definitions (#5537)
Move all function tests to a dedicated directory and all `struct` function tests to a dedicated file in this directory. Part of #5533.
1 parent 7f52cc7 commit ae454bb

File tree

3 files changed

+544
-124
lines changed

3 files changed

+544
-124
lines changed

toolchain/check/testdata/interop/cpp/no_prelude/function.carbon renamed to toolchain/check/testdata/interop/cpp/no_prelude/function/function.carbon

Lines changed: 2 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//
88
// AUTOUPDATE
99
// TIP: To test this file alone, run:
10-
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/no_prelude/function.carbon
10+
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/no_prelude/function/function.carbon
1111
// TIP: To dump output, run:
12-
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/no_prelude/function.carbon
12+
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/no_prelude/function/function.carbon
1313

1414
// ============================================================================
1515
// Global
@@ -154,62 +154,8 @@ fn F() {
154154
// TODO: Test that template functions are unsupported.
155155
// This is not tested because template functions are not considered a single result when doing lookup.
156156

157-
// ============================================================================
158-
// Struct param type
159-
// ============================================================================
160-
161-
// --- struct_param_type.h
162-
163-
struct S {};
164-
165-
auto foo(S) -> void;
166-
167-
// --- fail_todo_import_struct_param_type.carbon
168-
169-
library "[[@TEST_NAME]]";
170-
171-
import Cpp library "struct_param_type.h";
172-
173-
fn F() {
174-
// CHECK:STDERR: fail_todo_import_struct_param_type.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: parameter type: struct S` [SemanticsTodo]
175-
// CHECK:STDERR: Cpp.foo({});
176-
// CHECK:STDERR: ^~~~~~~
177-
// CHECK:STDERR: fail_todo_import_struct_param_type.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup]
178-
// CHECK:STDERR: Cpp.foo({});
179-
// CHECK:STDERR: ^~~~~~~
180-
// CHECK:STDERR:
181-
Cpp.foo({});
182-
}
183-
184157
// TODO: Add a test per unsupported param type. See https://github.com/carbon-language/carbon-lang/pull/5477/files/4321e21ed27d987fd71be182d292973fd9849df8#r2094655176
185158

186-
// ============================================================================
187-
// Struct return type
188-
// ============================================================================
189-
190-
// --- struct_return_type.h
191-
192-
struct F;
193-
194-
auto foo() -> F;
195-
196-
// --- fail_todo_import_struct_return_type.carbon
197-
198-
library "[[@TEST_NAME]]";
199-
200-
import Cpp library "struct_return_type.h";
201-
202-
fn F() {
203-
// CHECK:STDERR: fail_todo_import_struct_return_type.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: return type: struct F` [SemanticsTodo]
204-
// CHECK:STDERR: Cpp.foo();
205-
// CHECK:STDERR: ^~~~~~~
206-
// CHECK:STDERR: fail_todo_import_struct_return_type.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup]
207-
// CHECK:STDERR: Cpp.foo();
208-
// CHECK:STDERR: ^~~~~~~
209-
// CHECK:STDERR:
210-
Cpp.foo();
211-
}
212-
213159
// TODO: Add a test per unsupported return type. See https://github.com/carbon-language/carbon-lang/pull/5477/files/4321e21ed27d987fd71be182d292973fd9849df8#r2094655176
214160

215161
// CHECK:STDOUT: --- import_global.carbon
@@ -449,69 +395,3 @@ fn F() {
449395
// CHECK:STDOUT: return
450396
// CHECK:STDOUT: }
451397
// CHECK:STDOUT:
452-
// CHECK:STDOUT: --- fail_todo_import_struct_param_type.carbon
453-
// CHECK:STDOUT:
454-
// CHECK:STDOUT: constants {
455-
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
456-
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
457-
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
458-
// CHECK:STDOUT: }
459-
// CHECK:STDOUT:
460-
// CHECK:STDOUT: imports {
461-
// CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
462-
// CHECK:STDOUT: .foo = <error>
463-
// CHECK:STDOUT: import Cpp//...
464-
// CHECK:STDOUT: }
465-
// CHECK:STDOUT: }
466-
// CHECK:STDOUT:
467-
// CHECK:STDOUT: file {
468-
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
469-
// CHECK:STDOUT: .Cpp = imports.%Cpp
470-
// CHECK:STDOUT: .F = %F.decl
471-
// CHECK:STDOUT: }
472-
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
473-
// CHECK:STDOUT: import Cpp "struct_param_type.h"
474-
// CHECK:STDOUT: }
475-
// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
476-
// CHECK:STDOUT: }
477-
// CHECK:STDOUT:
478-
// CHECK:STDOUT: fn @F() {
479-
// CHECK:STDOUT: !entry:
480-
// CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
481-
// CHECK:STDOUT: %foo.ref: <error> = name_ref foo, <error> [concrete = <error>]
482-
// CHECK:STDOUT: %.loc14: %empty_struct_type = struct_literal ()
483-
// CHECK:STDOUT: return
484-
// CHECK:STDOUT: }
485-
// CHECK:STDOUT:
486-
// CHECK:STDOUT: --- fail_todo_import_struct_return_type.carbon
487-
// CHECK:STDOUT:
488-
// CHECK:STDOUT: constants {
489-
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
490-
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
491-
// CHECK:STDOUT: }
492-
// CHECK:STDOUT:
493-
// CHECK:STDOUT: imports {
494-
// CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
495-
// CHECK:STDOUT: .foo = <error>
496-
// CHECK:STDOUT: import Cpp//...
497-
// CHECK:STDOUT: }
498-
// CHECK:STDOUT: }
499-
// CHECK:STDOUT:
500-
// CHECK:STDOUT: file {
501-
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
502-
// CHECK:STDOUT: .Cpp = imports.%Cpp
503-
// CHECK:STDOUT: .F = %F.decl
504-
// CHECK:STDOUT: }
505-
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
506-
// CHECK:STDOUT: import Cpp "struct_return_type.h"
507-
// CHECK:STDOUT: }
508-
// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
509-
// CHECK:STDOUT: }
510-
// CHECK:STDOUT:
511-
// CHECK:STDOUT: fn @F() {
512-
// CHECK:STDOUT: !entry:
513-
// CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
514-
// CHECK:STDOUT: %foo.ref: <error> = name_ref foo, <error> [concrete = <error>]
515-
// CHECK:STDOUT: return
516-
// CHECK:STDOUT: }
517-
// CHECK:STDOUT:

toolchain/check/testdata/interop/cpp/no_prelude/function_inline.carbon renamed to toolchain/check/testdata/interop/cpp/no_prelude/function/inline.carbon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//
88
// AUTOUPDATE
99
// TIP: To test this file alone, run:
10-
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/no_prelude/function_inline.carbon
10+
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/no_prelude/function/inline.carbon
1111
// TIP: To dump output, run:
12-
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/no_prelude/function_inline.carbon
12+
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/no_prelude/function/inline.carbon
1313

1414
// ============================================================================
1515
// With definition

0 commit comments

Comments
 (0)