Files
swift-mirror/test/Serialization/comments-hidden.swift
Drew Crawford aa5cf2b842 [Serialization] Don't serialize non-public documentation
Let's say I am a good citizen and document my private symbols:

    /** My TOP SECRET DOCUMENTATION */
    private class Foo {
    }

When I go to distribute the compiled binary, I find out my private
documentation is distributed as well:

    $ swiftc test.swift -emit-module -module-name "test"
    $ strings test.swiftdoc
    My TOP SECRET DOCUMENTATION
    /** My TOP SECRET DOCUMENTATION */

If a client can't use a symbol (e.g. it's private [or internal and not
-enable-testing]) don't emit the documentation for a symbol in the
swiftdoc.

Fixes: SR-762, rdar://21453624

The test coverage implements this truth table:

| visibility | -enable-testing | documentation? |
|------------|-----------------|----------------|
| private    | no              |              |
| internal   | no              |              |
| public     | no              |              |
| private    | yes             |              |
| internal   | yes             |              |
| public     | yes             |              |

Modified the existing comments test coverage to expect non-public
documentation not to be emitted.

Don't rely on existing comment structure

Refuse to emit comments if the decl cannot actually have one.  To
accomplish this, we move `canHaveComment` into the Decl instance.  It
must also be marked `const`, since one of its existing usages operates
on a const pointer.

Perform fewer checks when serializing the standard library.
2016-03-17 17:46:23 -05:00

56 lines
2.1 KiB
Swift

// Test the case when we compile normally
//
// RUN: rm -rf %t
// RUN: mkdir %t
// RUN: %target-swift-frontend -module-name comments -emit-module -emit-module-path %t/comments.swiftmodule -emit-module-doc -emit-module-doc-path %t/comments.swiftdoc %s
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -source-filename %s -I %t > %t.normal.txt
// RUN: FileCheck %s -check-prefix=NORMAL < %t.normal.txt
// RUN: FileCheck %s -check-prefix=NORMAL-NEGATIVE < %t.normal.txt
// Test the case when we compile with -enable-testing
//
// RUN: rm -rf %t
// RUN: mkdir %t
// RUN: %target-swift-frontend -enable-testing -module-name comments -emit-module -emit-module-path %t/comments.swiftmodule -emit-module-doc -emit-module-doc-path %t/comments.swiftdoc %s
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -source-filename %s -I %t > %t.testing.txt
// RUN: FileCheck %s -check-prefix=TESTING < %t.testing.txt
// RUN: FileCheck %s -check-prefix=TESTING-NEGATIVE < %t.testing.txt
/// PublicClass Documentation
public class PublicClass {
/// Public Function Documentation
public func f_public() { }
/// Internal Function Documentation NotForNormal
internal func f_internal() { }
/// Private Function Documentation NotForNormal NotForTesting
private func f_private() { }
}
/// InternalClass Documentation NotForNormal
internal class InternalClass {
/// Internal Function Documentation NotForNormal
internal func f_internal() { }
/// Private Function Documentation NotForNormal NotForTesting
private func f_private() { }
}
/// PrivateClass Documentation NotForNormal NotForTesting
private class PrivateClass {
/// Private Function Documentation NotForNormal NotForTesting
private func f_private() { }
}
// NORMAL-NEGATIVE-NOT: NotForNormal
// NORMAL-NEGATIVE-NOT: NotForTesting
// NORMAL: PublicClass Documentation
// NORMAL: Public Function Documentation
// TESTING-NEGATIVE-NOT: NotForTesting
// TESTING: InternalClass Documentation
// TESTING: Internal Function Documentation
// TESTING: PublicClass Documentation
// TESTING: Public Function Documentation
// TESTING: Internal Function Documentation