From 0a6f73331ea9de589d16dfbc6ac8a342419646a5 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 2 Dec 2019 10:23:10 +0000 Subject: [PATCH 1/6] Add Swift 5.1 Package.swift --- .travis.yml | 24 ------------------------ Package.swift | 2 +- Package@swift-4.swift | 19 +++++++++++++++++++ README.md | 4 ++-- 4 files changed, 22 insertions(+), 27 deletions(-) delete mode 100644 .travis.yml create mode 100644 Package@swift-4.swift diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 99e1887..0000000 --- a/.travis.yml +++ /dev/null @@ -1,24 +0,0 @@ -os: - - linux - - osx -language: generic -sudo: required -dist: trusty - -osx_image: xcode9.4 -before_install: - - if [ $TRAVIS_OS_NAME == "osx" ]; then - brew install vapor/tap/vapor; - else - eval "$(curl -sL https://apt.vapor.sh)"; - sudo apt-get install vapor; - sudo chmod -R a+rx /usr/; - fi - -script: - - swift build - - swift build -c release - - swift test - -after_success: - - eval "$(curl -sL https://raw.githubusercontent.com/vapor-community/swift/swift-4-codecov/codecov-swift4)" diff --git a/Package.swift b/Package.swift index 0553068..c1b3e6d 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.0 +// swift-tools-version:5.1 import PackageDescription diff --git a/Package@swift-4.swift b/Package@swift-4.swift new file mode 100644 index 0000000..0553068 --- /dev/null +++ b/Package@swift-4.swift @@ -0,0 +1,19 @@ +// swift-tools-version:4.0 + +import PackageDescription + +let package = Package( + name: "LeafMarkdown", + products: [ + .library(name: "LeafMarkdown", targets: ["LeafMarkdown"]), + ], + dependencies: [ + .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"), + .package(url: "https://github.com/vapor/leaf.git", from: "3.0.0"), + .package(url: "https://github.com/vapor-community/markdown.git", .upToNextMajor(from: "0.4.0")), + ], + targets: [ + .target(name: "LeafMarkdown", dependencies: ["Vapor", "Leaf", "SwiftMarkdown"]), + .testTarget(name: "LeafMarkdownTests", dependencies: ["LeafMarkdown"]), + ] +) diff --git a/README.md b/README.md index 8c6b8d3..f416aa9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Leaf Markdown -[![Language](https://img.shields.io/badge/Swift-4-brightgreen.svg)](http://swift.org) -[![Build Status](https://travis-ci.org/vapor-community/leaf-markdown.svg?branch=master)](https://travis-ci.org/vapor-community/leaf-markdown) +[![Language](https://img.shields.io/badge/Swift-5.1-brightgreen.svg)](http://swift.org) +[![Build Status](https://github.com/vapor-community/leaf-markdown/workflows/CI/badge.svg?branch=master)](https://github.com/vapor-community/leaf-markdown/actions) [![codecov](https://codecov.io/gh/vapor-community/leaf-markdown/branch/master/graph/badge.svg)](https://codecov.io/gh/vapor-community/leaf-markdown) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/vapor-community/leaf-markdown/master/LICENSE) From 528049ba6e0b1805af0d3cef252fa4dd6a3886dc Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 2 Dec 2019 10:44:04 +0000 Subject: [PATCH 2/6] Remove LinuxMain as now using Swift 5.1 and update gitignore --- .gitignore | 1 + Tests/LinuxMain.swift | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) delete mode 100644 Tests/LinuxMain.swift diff --git a/.gitignore b/.gitignore index 1483084..af27742 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ Package.pins DerivedData/ Package.resolved +.swiftpm diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift deleted file mode 100644 index 6f98444..0000000 --- a/Tests/LinuxMain.swift +++ /dev/null @@ -1,8 +0,0 @@ -import XCTest - -@testable import LeafMarkdownTests - -XCTMain([ - testCase(LeafTests.allTests), - testCase(ServicesTests.allTests) -]) From 02034dd7becca9370f1afed8aba63d591800864c Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 2 Dec 2019 10:44:28 +0000 Subject: [PATCH 3/6] Tag should only depend on TemplateKit --- Sources/LeafMarkdown/Tag.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/LeafMarkdown/Tag.swift b/Sources/LeafMarkdown/Tag.swift index c98245a..6c4b736 100644 --- a/Sources/LeafMarkdown/Tag.swift +++ b/Sources/LeafMarkdown/Tag.swift @@ -1,6 +1,5 @@ -import Leaf +import TemplateKit import SwiftMarkdown -import Async public final class Markdown: TagRenderer { @@ -11,7 +10,7 @@ public final class Markdown: TagRenderer { public let name = "markdown" private let options: MarkdownOptions? - + public init(options: MarkdownOptions? = nil) { self.options = options } From bf77d8aa023e6a01dc79e18a187d1a016e5b31f1 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 2 Dec 2019 10:45:27 +0000 Subject: [PATCH 4/6] Add GH actions support --- .github/workflows/ci.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4eaaf58 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,28 @@ +name: CI +on: +- push +jobs: + xenial: + container: + image: vapor/swift:5.1-xenial + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - run: swift test --enable-test-discovery --enable-code-coverage + bionic: + container: + image: vapor/swift:5.1-bionic + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Run Bionic Tests + run: swift test --enable-test-discovery --enable-code-coverage + - name: Setup container for codecov upload + run: apt-get update && apt-get install curl + - name: Process coverage file + run: llvm-cov show .build/x86_64-unknown-linux/debug/LeafMarkdownPackageTests.xctest -instr-profile=.build/x86_64-unknown-linux/debug/codecov/default.profdata > coverage.txt + - name: Upload code coverage + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_UPLOAD_KEY }} + file: coverage.txt From e20b833291d86e92a069cf8c0ffe40071000489d Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 2 Dec 2019 10:46:35 +0000 Subject: [PATCH 5/6] Delete ServiceTests - that's just testing Leaf itself --- Tests/LeafMarkdownTests/ServicesTests.swift | 23 --------------------- 1 file changed, 23 deletions(-) delete mode 100644 Tests/LeafMarkdownTests/ServicesTests.swift diff --git a/Tests/LeafMarkdownTests/ServicesTests.swift b/Tests/LeafMarkdownTests/ServicesTests.swift deleted file mode 100644 index a5b40f7..0000000 --- a/Tests/LeafMarkdownTests/ServicesTests.swift +++ /dev/null @@ -1,23 +0,0 @@ -import XCTest -import Vapor -import Leaf - -import LeafMarkdown - -class ServicesTests: XCTestCase { - static var allTests = [ - ("testTagsCanBeAddedToServices", testTagsCanBeAddedToServices) - ] - - func testTagsCanBeAddedToServices() throws { - var services = Services.default() - try services.register(LeafProvider()) - var tags = LeafTagConfig.default() - tags.use(Markdown(), as: "markdown") - services.register(tags) - let app = try Application(services: services) - let renderer = try app.make(LeafRenderer.self) - - XCTAssertNotNil(renderer.tags[Markdown().name]) - } -} From 4da1b61336035abb47a24f5becc519b697c21837 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Mon, 2 Dec 2019 13:05:09 +0000 Subject: [PATCH 6/6] Only use the dependencies we need --- Package.swift | 8 ++++---- Tests/LeafMarkdownTests/LeafTests.swift | 18 +++++++----------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Package.swift b/Package.swift index c1b3e6d..3ad6fb5 100644 --- a/Package.swift +++ b/Package.swift @@ -8,12 +8,12 @@ let package = Package( .library(name: "LeafMarkdown", targets: ["LeafMarkdown"]), ], dependencies: [ - .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"), + .package(url: "https://github.com/vapor/template-kit.git", from: "1.4.0"), + .package(url: "https://github.com/vapor-community/markdown.git", from: "0.5.0"), .package(url: "https://github.com/vapor/leaf.git", from: "3.0.0"), - .package(url: "https://github.com/vapor-community/markdown.git", .upToNextMajor(from: "0.4.0")), ], targets: [ - .target(name: "LeafMarkdown", dependencies: ["Vapor", "Leaf", "SwiftMarkdown"]), - .testTarget(name: "LeafMarkdownTests", dependencies: ["LeafMarkdown"]), + .target(name: "LeafMarkdown", dependencies: ["TemplateKit", "SwiftMarkdown"]), + .testTarget(name: "LeafMarkdownTests", dependencies: ["LeafMarkdown", "Leaf"]), ] ) diff --git a/Tests/LeafMarkdownTests/LeafTests.swift b/Tests/LeafMarkdownTests/LeafTests.swift index db388a7..73c3592 100644 --- a/Tests/LeafMarkdownTests/LeafTests.swift +++ b/Tests/LeafMarkdownTests/LeafTests.swift @@ -1,29 +1,26 @@ import XCTest -import Vapor - @testable import Leaf import LeafMarkdown class LeafTests: XCTestCase { - static var allTests = [ - ("testRunTag", testRunTag), - ("testNilParameterDoesNotCrashLeaf", testNilParameterDoesNotCrashLeaf), - ("testStripHtml", testStripHtml), - ("testDoNotStripHtml", testDoNotStripHtml) - ] + // MARK: - Properties + var renderer: LeafRenderer! let template = "#markdown(data)" + // MARK: - Overrides + override func setUp() { let queue = EmbeddedEventLoop() let container = BasicContainer(config: .init(), environment: .testing, services: .init(), on: queue) let tag = Markdown() var leafTagConfig = LeafTagConfig.default() leafTagConfig.use(tag, as: tag.name) - self.renderer = LeafRenderer(config: LeafConfig(tags: leafTagConfig, viewsDir: "", shouldCache: false), - using: container) + self.renderer = LeafRenderer(config: LeafConfig(tags: leafTagConfig, viewsDir: "", shouldCache: false), using: container) } + + // MARK: - Tests func testRunTag() throws { let inputMarkdown = "# This is a test\n\nWe have some text in a tag" @@ -72,6 +69,5 @@ class LeafTests: XCTestCase { let result = try renderer.render(template: template.data(using: .utf8)!, data).wait() let resultString = String(data: result.data, encoding: .utf8)! XCTAssertEqual(resultString, expectedHtml) - } }