Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
norio-nomura committed Nov 4, 2019
1 parent 5ca5a76 commit bf60c10
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,41 @@ jobs:
- uses: actions/checkout@master
- name: Docker Build
run: docker build -t action-swiftlint .

- name: Exit Status on Errors
run: |
STATUS=$(docker run -v $(pwd):$(pwd) -w $(pwd) --rm action-swiftlint &>/dev/null; echo $?)
[[ $STATUS == "2" ]]
working-directory: ./test/errors
shell: bash

- name: Exit Status on No lintable files
run: |
STATUS=$(docker run -v $(pwd):$(pwd) -w $(pwd) --rm action-swiftlint &>/dev/null; echo $?)
[[ $STATUS == "1" ]]
working-directory: ./test/no-lintable-files
shell: bash

- name: Exit Status on Warnings
run: |
STATUS=$(docker run -v $(pwd):$(pwd) -w $(pwd) --rm action-swiftlint &>/dev/null; echo $?)
[[ $STATUS == "0" ]]
working-directory: ./test/Warnings
shell: bash

- name: Exit Status on Warnings with `--strict`
run: |
STATUS=$(docker run -v $(pwd):$(pwd) -w $(pwd) --rm action-swiftlint --strict &>/dev/null; echo $?)
[[ $STATUS == "3" ]]
working-directory: ./test/Warnings
shell: bash

- name: Output on Errors
run: diff <(docker run -v $(pwd):$(pwd) -w $(pwd) --rm action-swiftlint|sort) expected.txt
working-directory: ./test/errors
shell: bash

- name: Output on Warnings
run: diff <(docker run -v $(pwd):$(pwd) -w $(pwd) --rm action-swiftlint|sort) expected.txt
working-directory: ./test/Warnings
shell: bash
5 changes: 5 additions & 0 deletions test/Warnings/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
28 changes: 28 additions & 0 deletions test/Warnings/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Warnings",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "Warnings",
targets: ["Warnings"]),
],
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: "Warnings",
dependencies: []),
.testTarget(
name: "WarningsTests",
dependencies: ["Warnings"]),
]
)
3 changes: 3 additions & 0 deletions test/Warnings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Warnings

A description of this package.
3 changes: 3 additions & 0 deletions test/Warnings/Sources/Warnings/Warnings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
struct Warnings {
var text = "Hello, World!"
}
7 changes: 7 additions & 0 deletions test/Warnings/Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import XCTest

import WarningsTests

var tests = [XCTestCaseEntry]()
tests += WarningsTests.allTests()
XCTMain(tests)
15 changes: 15 additions & 0 deletions test/Warnings/Tests/WarningsTests/WarningsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import XCTest
@testable import Warnings

final class WarningsTests: XCTestCase {
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
XCTAssertEqual(Warnings().text, "Hello, World!")
}

static var allTests = [
("testExample", testExample),
]
}
9 changes: 9 additions & 0 deletions test/Warnings/Tests/WarningsTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import XCTest

#if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] {
return [
testCase(WarningsTests.allTests),
]
}
#endif
5 changes: 5 additions & 0 deletions test/Warnings/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
::warning file=Package.swift,line=12,column=35::Trailing Comma Violation: Collection literals should not have trailing commas. (trailing_comma)
::warning file=Package.swift,line=20,column=1::Line Length Violation: Line should be 120 characters or less: currently 122 characters (line_length)
::warning file=Package.swift,line=26,column=40::Trailing Comma Violation: Collection literals should not have trailing commas. (trailing_comma)
::warning file=Tests/WarningsTests/WarningsTests.swift,line=13,column=37::Trailing Comma Violation: Collection literals should not have trailing commas. (trailing_comma)
::warning file=Tests/WarningsTests/XCTestManifests.swift,line=6,column=41::Trailing Comma Violation: Collection literals should not have trailing commas. (trailing_comma)
5 changes: 5 additions & 0 deletions test/errors/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
28 changes: 28 additions & 0 deletions test/errors/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "errors",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "errors",
targets: ["errors"]),
],
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: "errors",
dependencies: []),
.testTarget(
name: "errorsTests",
dependencies: ["errors"]),
]
)
3 changes: 3 additions & 0 deletions test/errors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# errors

A description of this package.
3 changes: 3 additions & 0 deletions test/errors/Sources/errors/errors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
struct errors {
var text = "Hello, World!"
}
7 changes: 7 additions & 0 deletions test/errors/Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import XCTest

import errorsTests

var tests = [XCTestCaseEntry]()
tests += errorsTests.allTests()
XCTMain(tests)
9 changes: 9 additions & 0 deletions test/errors/Tests/errorsTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import XCTest

#if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] {
return [
testCase(errorsTests.allTests),
]
}
#endif
15 changes: 15 additions & 0 deletions test/errors/Tests/errorsTests/errorsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import XCTest
@testable import errors

final class errorsTests: XCTestCase {
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
XCTAssertEqual(errors().text, "Hello, World!")
}

static var allTests = [
("testExample", testExample),
]
}
7 changes: 7 additions & 0 deletions test/errors/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
::error file=Sources/errors/errors.swift,line=1,column=8::Type Name Violation: Type name should start with an uppercase character: 'errors' (type_name)
::error file=Tests/errorsTests/errorsTests.swift,line=4,column=13::Type Name Violation: Type name should start with an uppercase character: 'errorsTests' (type_name)
::warning file=Package.swift,line=12,column=33::Trailing Comma Violation: Collection literals should not have trailing commas. (trailing_comma)
::warning file=Package.swift,line=20,column=1::Line Length Violation: Line should be 120 characters or less: currently 122 characters (line_length)
::warning file=Package.swift,line=26,column=38::Trailing Comma Violation: Collection literals should not have trailing commas. (trailing_comma)
::warning file=Tests/errorsTests/XCTestManifests.swift,line=6,column=39::Trailing Comma Violation: Collection literals should not have trailing commas. (trailing_comma)
::warning file=Tests/errorsTests/errorsTests.swift,line=13,column=37::Trailing Comma Violation: Collection literals should not have trailing commas. (trailing_comma)
Empty file.

0 comments on commit bf60c10

Please sign in to comment.