Files
swift-mirror/test/SILGen/magic_identifier_file_conflicting.swift.gyb
Saleem Abdulrasool 6c02e6212d test: adjust the test to improve the viability on Windows
Convert the line endings manually since the parser is sensitive to the
trailing whitespace (the writing of the file will create a `\r\n` rather
than `\n`).  This largely fixes the issues for Windows with the issue
that the processing of the file location is currently not properly
processing escape characters and results in issues.

In theory, it should be possible for `getStringLiteralIfNotInterpolated`
to process the literal segments with `getEncodedStringSegment` for each
segment and then return a literal value cooked.  However, doing so will
require that the function return a `std::string` rather than `StringRef`
since the cooking means that we cannot simply provide a reference to the
SourceManager view.
2020-03-11 22:51:41 -07:00

105 lines
6.1 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %gyb -D TEMPDIR=%t %s > %t/magic_identifier_file_conflicting.swift
// RUN: %{python} -c "import sys; t = open(sys.argv[1], 'rb').read().replace('\r\n', '\n'); open(sys.argv[1], 'wb').write(t)" %t/magic_identifier_file_conflicting.swift
// We want to check both the diagnostics and the SIL output.
// RUN: %target-swift-emit-silgen -verify -emit-sorted-sil -enable-experimental-concise-pound-file -module-name Foo %t/magic_identifier_file_conflicting.swift %S/Inputs/magic_identifier_file_conflicting_other.swift | %FileCheck %s
// FIXME: Make this test work on Windows. There's no fundamental reason it
// can't; we just need someone with a Windows machine to do it so we
// don't have a 30-minute debug cycle.
// UNSUPPORTED: OS=windows-msvc
%{
TEMPDIR_ESC = TEMPDIR.replace('\\', '\\\\')
import os
def fixit_loc(start_col, orig_suffix):
"""
Computes a "start-end" string for a fix-it replacing a string literal which
starts at start_col and joins orig_suffix to TEMPDIR with a slash.
"""
original = '"{0}"'.format(os.path.join(TEMPDIR, orig_suffix))
end_col = start_col + len(original)
return '{0}-{1}'.format(start_col, end_col)
}%
//
// Same name as a physical file
//
// There should be no warning for the exact same path.
// no-warning
#sourceLocation(file: "${TEMPDIR_ESC}/magic_identifier_file_conflicting.swift", line: 10)
#sourceLocation()
// expected-warning@+2 {{'#sourceLocation' directive produces '#file' string of 'Foo/magic_identifier_file_conflicting.swift', which conflicts with '#file' strings produced by other paths in the module}}
// expected-note@+1 {{change file in '#sourceLocation' to '${TEMPDIR_ESC}/magic_identifier_file_conflicting.swift'}} {{${fixit_loc(23, "other_path_b/magic_identifier_file_conflicting.swift")}="${TEMPDIR_ESC}/magic_identifier_file_conflicting.swift"}}
#sourceLocation(file: "${TEMPDIR_ESC}/other_path_b/magic_identifier_file_conflicting.swift", line: 20)
#sourceLocation()
// expected-warning@+2 {{'#sourceLocation' directive produces '#file' string of 'Foo/magic_identifier_file_conflicting.swift', which conflicts with '#file' strings produced by other paths in the module}}
// expected-note@+1 {{change file in '#sourceLocation' to '${TEMPDIR_ESC}/magic_identifier_file_conflicting.swift'}} {{23-64="${TEMPDIR_ESC}/magic_identifier_file_conflicting.swift"}}
#sourceLocation(file: "magic_identifier_file_conflicting.swift", line: 30)
#sourceLocation()
//
// No physical file with the same name
//
// There shoud be no warning for a purely virtual file.
// no-warning
#sourceLocation(file: "other_file_a.swift", line: 40)
#sourceLocation()
// Even if you use it twice.
// no-warning
#sourceLocation(file: "other_file_a.swift", line: 50)
#sourceLocation()
// But there should be warnings for different-path, same-name virtual files.
// The lexicographically first path should be treated as canonical--we diagnose
// but don't offer a fix-it.
// expected-warning@+1 {{'#sourceLocation' directive produces '#file' string of 'Foo/other_file_b.swift', which conflicts with '#file' strings produced by other paths in the module}}
#sourceLocation(file: "first/other_file_b.swift", line: 60)
#sourceLocation()
// Subsequent paths should fix-it to the first one.
// expected-warning@+2 {{'#sourceLocation' directive produces '#file' string of 'Foo/other_file_b.swift', which conflicts with '#file' strings produced by other paths in the module}}
// expected-note@+1 {{change file in '#sourceLocation' to 'first/other_file_b.swift'}} {{23-50="first/other_file_b.swift"}}
#sourceLocation(file: "second/other_file_b.swift", line: 70)
#sourceLocation()
// Even if there's more than one.
// expected-warning@+2 {{'#sourceLocation' directive produces '#file' string of 'Foo/other_file_b.swift', which conflicts with '#file' strings produced by other paths in the module}}
// expected-note@+1 {{change file in '#sourceLocation' to 'first/other_file_b.swift'}} {{23-49="first/other_file_b.swift"}}
#sourceLocation(file: "third/other_file_b.swift", line: 80)
#sourceLocation()
// Even if one is duplicated.
// expected-warning@+2 {{'#sourceLocation' directive produces '#file' string of 'Foo/other_file_b.swift', which conflicts with '#file' strings produced by other paths in the module}}
// expected-note@+1 {{change file in '#sourceLocation' to 'first/other_file_b.swift'}} {{23-49="first/other_file_b.swift"}}
#sourceLocation(file: "third/other_file_b.swift", line: 90)
#sourceLocation()
// We should diagnose cross-file conflicts.
// expected-warning@+1 {{'#sourceLocation' directive produces '#file' string of 'Foo/other_file_c.swift', which conflicts with '#file' strings produced by other paths in the module}}
#sourceLocation(file: "first/other_file_c.swift", line: 100)
#sourceLocation()
//
// Check '#file' => '#filePath' mapping table
//
// CHECK-LABEL: // Mappings from '#file' to '#filePath':
// CHECK-NEXT: // 'Foo/magic_identifier_file_conflicting.swift' => 'BUILD_DIR{{[/\\]}}test-{{[^/]+}}{{[/\\]}}SILGen{{[/\\]}}Output{{[/\\]}}magic_identifier_file_conflicting.swift.gyb.tmp{{[/\\]}}magic_identifier_file_conflicting.swift'
// CHECK-NEXT: // 'Foo/magic_identifier_file_conflicting.swift' => 'BUILD_DIR{{[/\\]}}test-{{[^/]+}}{{[/\\]}}SILGen{{[/\\]}}Output{{[/\\]}}magic_identifier_file_conflicting.swift.gyb.tmp{{[/\\]}}other_path_b{{[/\\]}}magic_identifier_file_conflicting.swift' (alternate)
// CHECK-NEXT: // 'Foo/magic_identifier_file_conflicting.swift' => 'magic_identifier_file_conflicting.swift' (alternate)
// CHECK-NEXT: // 'Foo/magic_identifier_file_conflicting_other.swift' => 'SOURCE_DIR{{[/\\]}}test{{[/\\]}}SILGen{{[/\\]}}Inputs{{[/\\]}}magic_identifier_file_conflicting_other.swift'
// CHECK-NEXT: // 'Foo/other_file_a.swift' => 'other_file_a.swift'
// CHECK-NEXT: // 'Foo/other_file_b.swift' => 'first/other_file_b.swift'
// CHECK-NEXT: // 'Foo/other_file_b.swift' => 'second/other_file_b.swift' (alternate)
// CHECK-NEXT: // 'Foo/other_file_b.swift' => 'third/other_file_b.swift' (alternate)
// CHECK-NEXT: // 'Foo/other_file_c.swift' => 'first/other_file_c.swift'
// CHECK-NEXT: // 'Foo/other_file_c.swift' => 'second/other_file_c.swift' (alternate)