Skip to content
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

[Swift APIView] Add automated tests #9487

Merged
merged 7 commits into from
Dec 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "--source=/Users/travisprescott/Documents/AzureCommunicationCalling.xcframework"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "--source=/Users/travisprescott/repos/communication-ui-library-ios/AzureCommunicationUI"
Expand All @@ -68,12 +68,12 @@
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "--package-name=AzureCommunicationCallingTEST"
argument = "--package-name=SwiftAPIViewTests"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "--source=/Users/travisprescott/repos/azure-sdk-tools/src/swift/SwiftAPIViewTests/Sources"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<LocationScenarioReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class APIViewModel: Tokenizable, Encodable {
// self.diagnostics.append(Diagnostic(line_id, text))

func comment(_ text: String) {
checkIndent()
var message = text
if !text.starts(with: "\\") {
message = "\\\\ \(message)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ class DeclarationModel: Tokenizable, Linkable, Equatable {
case .attributeList:
// attributes on declarations should have newlines
let obj = AttributeListSyntax(child)!
for attr in obj.children(viewMode: .sourceAccurate) {
attr.tokenize(apiview: a, parent: parent)
let children = obj.children(viewMode: .sourceAccurate)
for attr in children {
let attrText = attr.withoutTrivia().description.filter { !$0.isWhitespace }
a.lineIdMarker(definitionId: "\(definitionId!).\(attrText)")
attr.tokenize(apiview: a, parent: parent)
a.newline()
a.blankLines(set: 0)
}
case .token:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,32 @@ extension SyntaxProtocol {
case .customAttribute: fallthrough
case .attribute:
// default implementation should not have newlines
for child in self.children(viewMode: .sourceAccurate) {
let children = self.children(viewMode: .sourceAccurate)
for child in children {
if child.childNameInParent == "name" {
let attrName = child.withoutTrivia().description
a.keyword(attrName, spacing: .Neither)
// don't add space if the attribute has parameters
a.keyword(attrName, spacing: children.count == 2 ? .Trailing : .Neither)
} else {
child.tokenize(apiview: a, parent: parent)
}
}
a.whitespace()
case .classRestrictionType:
// in this simple context, class should not have a trailing space
a.keyword("class", spacing: .Neither)
case .codeBlock:
// Don't render code blocks. APIView is unconcerned with implementation
break
case .constrainedSugarType:
let obj = ConstrainedSugarTypeSyntax(self)!
let children = obj.children(viewMode: .sourceAccurate)
assert(children.count == 2)
for child in children {
child.tokenize(apiview: a, parent: parent)
if (child.kind == .token) {
a.whitespace()
}
}
case .enumCaseElement:
for child in self.children(viewMode: .sourceAccurate) {
let childIndex = child.indexInParent
Expand All @@ -75,6 +86,7 @@ extension SyntaxProtocol {
case .functionParameter:
let param = FunctionParameterSyntax(self)!
for child in param.children(viewMode: .sourceAccurate) {
let childKind = child.kind
let childIndex = child.indexInParent
// index 7 is the interal name, which we don't render at all
guard childIndex != 7 else { continue }
Expand All @@ -88,6 +100,16 @@ extension SyntaxProtocol {
} else {
SharedLogger.warn("Unhandled tokenKind '\(token.tokenKind)' for function parameter label")
}
} else if childKind == .attributeList {
let attrs = AttributeListSyntax(child)!
let lastAttrs = attrs.count - 1
for attr in attrs {
let attrIndex = attrs.indexInParent
attr.tokenize(apiview: a, parent: parent)
if attrIndex != lastAttrs {
a.whitespace()
}
}
} else {
child.tokenize(apiview: a, parent: parent)
}
Expand Down Expand Up @@ -166,6 +188,22 @@ extension SyntaxProtocol {
tokenize(token: token, apiview: a, parent: (parent as? DeclarationModel))
case .typealiasDecl:
DeclarationModel(from: TypealiasDeclSyntax(self)!, parent: parent).tokenize(apiview: a, parent: parent)
case .accessorBlock:
let obj = AccessorBlockSyntax(self)!
for child in obj.children(viewMode: .sourceAccurate) {
if child.kind == .token {
let token = TokenSyntax(child)!
let tokenKind = token.tokenKind
let tokenText = token.withoutTrivia().description
if tokenKind == .leftBrace || tokenKind == .rightBrace {
a.punctuation(tokenText, spacing: .Both)
} else {
child.tokenize(token: token, apiview: a, parent: nil)
}
} else {
child.tokenize(apiview: a, parent: parent)
}
}
default:
// default behavior for all nodes is to render all children
tokenizeChildren(apiview: a, parent: parent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ extension SwiftSyntax.TokenKind {
case "objc": return .TrimLeft
case "lowerThan", "higherThan", "associativity": return .Neither
case "available", "unavailable", "introduced", "deprecated", "obsoleted", "message", "renamed": return .Neither
case "willSet", "didSet", "get", "set":
return .Leading
default: return .Both
}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 55;
objectVersion = 73;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -72,6 +72,100 @@
0AA1BFBF2953955500AE8C11 /* PatternBindingListSyntax+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PatternBindingListSyntax+Extensions.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
0ACFCCB72CFE32E2006BFBE8 /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
AttributesTestFile.swifttxt,
EnumerationsTestFile.swifttxt,
ExtensionTestFile.swifttxt,
FunctionsTestFile.swifttxt,
GenericsTestFile.swifttxt,
InitializersTestFile.swifttxt,
OperatorTestFile.swifttxt,
PrivateInternalTestFile.swifttxt,
PropertiesTestFile.swifttxt,
ProtocolTestFile.swifttxt,
SwiftUITestFile.swifttxt,
);
target = 0A8469E827879AE200C967A8 /* SwiftAPIViewCoreTests */;
};
0ACFCCBA2CFE332E006BFBE8 /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
AttributesTestFile.swifttxt,
EnumerationsTestFile.swifttxt,
ExtensionTestFile.swifttxt,
FunctionsTestFile.swifttxt,
GenericsTestFile.swifttxt,
InitializersTestFile.swifttxt,
OperatorTestFile.swifttxt,
PrivateInternalTestFile.swifttxt,
PropertiesTestFile.swifttxt,
ProtocolTestFile.swifttxt,
SwiftUITestFile.swifttxt,
);
target = 0A8469E027879AE200C967A8 /* SwiftAPIViewCore */;
};
0ACFCCBD2CFE3BC0006BFBE8 /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
AttributesExpectFile.txt,
EnumerationsExpectFile.txt,
ExtensionExpectFile.txt,
FunctionsExpectFile.txt,
GenericsExpectFile.txt,
InitializersExpectFile.txt,
OperatorExpectFile.txt,
PrivateInternalExpectFile.txt,
PropertiesExpectFile.txt,
ProtocolExpectFile.txt,
SwiftUIExpectFile.txt,
);
target = 0A8469E827879AE200C967A8 /* SwiftAPIViewCoreTests */;
};
0ACFCCBF2CFE3BC3006BFBE8 /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
AttributesExpectFile.txt,
EnumerationsExpectFile.txt,
ExtensionExpectFile.txt,
FunctionsExpectFile.txt,
GenericsExpectFile.txt,
InitializersExpectFile.txt,
OperatorExpectFile.txt,
PrivateInternalExpectFile.txt,
PropertiesExpectFile.txt,
ProtocolExpectFile.txt,
SwiftUIExpectFile.txt,
);
target = 0A8469E027879AE200C967A8 /* SwiftAPIViewCore */;
};
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */

/* Begin PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet section */
0ACFCCC22CFE614B006BFBE8 /* PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet */ = {
isa = PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet;
buildPhase = 0A8469DD27879AE200C967A8 /* Sources */;
membershipExceptions = (
EnumerationsTestFile.swifttxt,
FunctionsTestFile.swifttxt,
GenericsTestFile.swifttxt,
InitializersTestFile.swifttxt,
OperatorTestFile.swifttxt,
PrivateInternalTestFile.swifttxt,
PropertiesTestFile.swifttxt,
ProtocolTestFile.swifttxt,
SwiftUITestFile.swifttxt,
);
};
/* End PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet section */

/* Begin PBXFileSystemSynchronizedRootGroup section */
0ACFCCB22CFE3288006BFBE8 /* TestFiles */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (0ACFCCBA2CFE332E006BFBE8 /* PBXFileSystemSynchronizedBuildFileExceptionSet */, 0ACFCCC22CFE614B006BFBE8 /* PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet */, 0ACFCCB72CFE32E2006BFBE8 /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = TestFiles; sourceTree = "<group>"; };
0ACFCCB32CFE32B9006BFBE8 /* ExpectFiles */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (0ACFCCBF2CFE3BC3006BFBE8 /* PBXFileSystemSynchronizedBuildFileExceptionSet */, 0ACFCCBD2CFE3BC0006BFBE8 /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = ExpectFiles; sourceTree = "<group>"; };
/* End PBXFileSystemSynchronizedRootGroup section */

/* Begin PBXFrameworksBuildPhase section */
0A8469DE27879AE200C967A8 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
Expand Down Expand Up @@ -146,6 +240,8 @@
0A846A0227879D0400C967A8 /* Tests */ = {
isa = PBXGroup;
children = (
0ACFCCB32CFE32B9006BFBE8 /* ExpectFiles */,
0ACFCCB22CFE3288006BFBE8 /* TestFiles */,
0A846A0327879D0400C967A8 /* SwiftAPIViewCoreTests.swift */,
);
path = Tests;
Expand Down Expand Up @@ -239,6 +335,10 @@
dependencies = (
0A8469EC27879AE200C967A8 /* PBXTargetDependency */,
);
fileSystemSynchronizedGroups = (
0ACFCCB22CFE3288006BFBE8 /* TestFiles */,
0ACFCCB32CFE32B9006BFBE8 /* ExpectFiles */,
);
name = SwiftAPIViewCoreTests;
productName = SwiftAPIViewCoreTests;
productReference = 0A8469E927879AE200C967A8 /* SwiftAPIViewCoreTests.xctest */;
Expand All @@ -263,7 +363,6 @@
};
};
buildConfigurationList = 0A8469DB27879AE200C967A8 /* Build configuration list for PBXProject "SwiftAPIViewCore" */;
compatibilityVersion = "Xcode 13.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
Expand All @@ -276,6 +375,7 @@
0A1CA129292D8B5800CC2367 /* XCRemoteSwiftPackageReference "swift-syntax" */,
0A6C6596292E98890075C56F /* XCRemoteSwiftPackageReference "SourceKitten" */,
);
preferredProjectObjectVersion = 55;
productRefGroup = 0A8469E227879AE200C967A8 /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1610"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0A8469E027879AE200C967A8"
BuildableName = "SwiftAPIViewCore.framework"
BlueprintName = "SwiftAPIViewCore"
ReferencedContainer = "container:SwiftAPIViewCore.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0A8469E827879AE200C967A8"
BuildableName = "SwiftAPIViewCoreTests.xctest"
BlueprintName = "SwiftAPIViewCoreTests"
ReferencedContainer = "container:SwiftAPIViewCore.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0A8469E027879AE200C967A8"
BuildableName = "SwiftAPIViewCore.framework"
BlueprintName = "SwiftAPIViewCore"
ReferencedContainer = "container:SwiftAPIViewCore.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Package parsed using Swift APIView (version 0.2.2)


package AttributesTestFile.swifttxt {
public class ExampleClass: NSObject {
@objc public var enabled: Bool
}

@available(iOS 10.0, macOS 10.12, *)
public class MyClass {}

@available(*, unavailable, renamed: "MyRenamedProtocol")
public typealias MyProtocol = MyRenamedProtocol

public protocol MyRenamedProtocol {}

@available(swift 3.0.2)
@available(macOS 10.12, *)
public struct MyStruct {}

public class SomeSendable: @unchecked Sendable {
public let name: String
public init(name: String)
}
}
Loading
Loading