Skip to content

Commit

Permalink
Add separate lint stage to .travis.yml (#87)
Browse files Browse the repository at this point in the history
The prevents linting stage from running multiple times in all parallel jobs. We're mostly going to develop with the latest version of Xcode, so we only care about linter and formatter warnings with that version. Thus, the linter stage runs first with the latest version, while actual tests run in parallel jobs of the next "test" stage.

* Travis jobs/stages experiment
* Fix pod lint warnings with Xcode 10.2
* Reorder matrix and jobs in .travis.yml
* Specify jobs/stages with YAML references
* Test .travis.yml without YAML references
* Test stages/jobs one by one
* Add install: skip to stages in .travis.yml
* Update .travis.yml
* Add codecov upload to one of the jobs
* Add back lint stage
* Rename `unit-test` stage to `test`
* Add separate Package.swift for Swift 5.0
* Add explicit top level osx_image to .travis.yml
  • Loading branch information
MaxDesiatov authored Apr 2, 2019
1 parent 705bd7d commit 847d754
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 37 deletions.
72 changes: 38 additions & 34 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,46 @@
osx_image: xcode10.2
language: swift

matrix:
env:
global:
- FRAMEWORK_NAME=XMLCoder

jobs:
include:
- osx_image: xcode10
- stage: lint
osx_image: xcode10.2
language: swift
env: TEST_DEVICE='platform=iOS Simulator,OS=12.0,name=iPhone SE'
- osx_image: xcode10.1
before_install:
- brew update
- brew install swiftformat
- brew outdated swiftlint || brew upgrade swiftlint
script:
- swiftformat --lint --verbose .
- swiftlint
- pod lib lint --verbose
- &test
stage: test
osx_image: xcode10
language: swift
install: skip
env: TEST_DEVICE='platform=iOS Simulator,OS=12.0,name=iPhone SE'
script:
- >
xcodebuild test -enableCodeCoverage YES -scheme XMLCoder
-sdk iphonesimulator -destination "$TEST_DEVICE" | xcpretty
- >
xcodebuild test -enableCodeCoverage YES -scheme XMLCoder
-sdk macosx | xcpretty
# this runs the tests the second time, but it's the only way to make sure
# that `Package.swift` is in a good state and `swift test` can only generate
# coverage reports in Swift 5.0, see this issue for more details:
# https://github.com/apple/swift-package-manager/pull/1787
- swift test
- <<: *test
osx_image: xcode10.1
env: TEST_DEVICE='platform=iOS Simulator,OS=12.1,name=iPhone SE'
- osx_image: xcode10.2
language: swift
- <<: *test
osx_image: xcode10.2
env: TEST_DEVICE='platform=iOS Simulator,OS=12.2,name=iPhone SE'
after_success:
- bash <(curl -s https://codecov.io/bash)
Expand All @@ -26,33 +58,5 @@ matrix:
repo: MaxDesiatov/XMLCoder
tags: true

env:
global:
- FRAMEWORK_NAME=XMLCoder
before_install:
- gem install cocoapods --pre # Since Travis is not always on latest version
- brew update
- brew install swiftformat
- brew outdated swiftlint || brew upgrade swiftlint
script:
- swiftformat --lint --verbose .
- swiftlint
- pod lib lint --verbose
- >
xcodebuild test -enableCodeCoverage YES -scheme XMLCoder
-sdk iphonesimulator -destination "$TEST_DEVICE" | xcpretty
- xcodebuild test -enableCodeCoverage YES -scheme XMLCoder -sdk macosx | xcpretty

# this runs the tests the second time, but it's the only way to make sure
# that `Package.swift` is in a good state and `swift test` can only generate
# coverage reports in Swift 5.0, see this issue for more details:
# https://github.com/apple/swift-package-manager/pull/1787
- swift test

# this is commented because installing Jazzy on Travis doesn't work ¯\_(ツ)_/¯
# - ./docs.sh

# jobs:
# include:
# - stage: deploy
# osx_image: xcode10.1
5 changes: 2 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.2
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down Expand Up @@ -27,6 +27,5 @@ let package = Package(
name: "XMLCoderTests",
dependencies: ["XMLCoder"]
),
],
swiftLanguageVersions: [.v4_2, .version("5")]
]
)
31 changes: 31 additions & 0 deletions Package@swift-4.2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// swift-tools-version:4.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "XMLCoder",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "XMLCoder",
targets: ["XMLCoder"]
),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "XMLCoder",
dependencies: []
),
.testTarget(
name: "XMLCoderTests",
dependencies: ["XMLCoder"]
),
]
)
5 changes: 5 additions & 0 deletions Sources/XMLCoder/Auxiliaries/XMLStackParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ class XMLStackParser: NSObject {
upperBoundIndex = errorPosition + offset
}

#if compiler(>=5.0)
let lowerBound = String.Index(utf16Offset: lowerBoundIndex, in: string)
let upperBound = String.Index(utf16Offset: upperBoundIndex, in: string)
#else
let lowerBound = String.Index(encodedOffset: lowerBoundIndex)
let upperBound = String.Index(encodedOffset: upperBoundIndex)
#endif

let context = string[lowerBound..<upperBound]

Expand Down

0 comments on commit 847d754

Please sign in to comment.