Skip to content

Run concept exercises in CI #487

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

Merged
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
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ on: [push, pull_request]
jobs:
test:
runs-on: macos-latest
env:
RUNALL: "true"
steps:
- name: Checkout code
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f

- name: Prepare
run: swift package generate-xcodeproj

- name: Run tests
run: ./xswift-test-spm
run: swift test
156 changes: 72 additions & 84 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,84 +1,72 @@
// swift-tools-version:4.2

import PackageDescription
import Foundation

extension String {
var pascalCased: String {
let items = self.components(separatedBy: "-")
return items.reduce("", { $0 + $1.capitalized })
}
}
let currentDirectory = FileManager.default.currentDirectoryPath
let configPath = currentDirectory + "/config.json"
var allProblems = [String]()

if
let jsonData = try? Data(contentsOf: URL(fileURLWithPath: configPath), options: Data.ReadingOptions.mappedIfSafe),
let json = try? JSONSerialization.jsonObject(with: jsonData, options: []),
let jsonDict = json as? [String: Any],
let exercisesDict = jsonDict["exercises"] as? [String: Any],
let practiceExercisesDict = exercisesDict["practice"] as? [[String: Any]],
let exercises = practiceExercisesDict.map({ $0["slug"] }) as? [String] {
allProblems += exercises
} else {
print("Could not parse config.json at \(configPath)")
}
let allProblemsPascalCase = allProblems.map { $0.pascalCased }

#if os(Linux)
// Create ./Tests/LinuxMain.swift
let allTestCases = allProblemsPascalCase.map { "testCase(\($0)Tests.allTests)," }

let linuxMainText =
"""
import XCTest
@testable import xswiftTests

XCTMain([
\(allTestCases.joined(separator: "\n"))
])
"""

let linuxMainFilePath = currentDirectory + "/LinuxMain.swift"

do {
if FileManager.default.fileExists(atPath: linuxMainFilePath) {
try FileManager.default.removeItem(atPath: linuxMainFilePath)
}
try linuxMainText.write(to: URL(fileURLWithPath: linuxMainFilePath), atomically: false, encoding: .utf8)
} catch let fileError {
print("Could not write file. \(fileError)")
}
#endif

let packageDependencies: [Package.Dependency] = allProblems.map { .package(path: "./exercises/practice/\($0)/") }
let targetDependencies: [Target.Dependency] = allProblemsPascalCase.map { .byName(name:"\($0)") }

let sources = allProblems.map { "./\($0)/.meta/Sources" }
let testSources = allProblems.map { "./\($0)/Tests" }

let package = Package(
name: "xswift",
products: [
.library(
name: "xswift",
targets: ["xswift"]
)
],
dependencies: packageDependencies,
targets: [
.target(
name: "xswift",
dependencies: targetDependencies,
path: "./exercises/practice",
sources: sources
),
.testTarget(
name: "xswiftTests",
dependencies: ["xswift"],
path: "./exercises/practice",
sources: testSources
),
]
)
// swift-tools-version:5.3

import PackageDescription
import Foundation

extension String {
var pascalCased: String {
let items = self.components(separatedBy: "-")
return items.reduce("", { $0 + $1.capitalized })
}
}

let currentDirectory = FileManager.default.currentDirectoryPath
let configPath = currentDirectory + "/config.json"
var conceptExercises = [String]()
var practiceExercises = [String]()

if
let jsonData = try? Data(contentsOf: URL(fileURLWithPath: configPath), options: Data.ReadingOptions.mappedIfSafe),
let json = try? JSONSerialization.jsonObject(with: jsonData, options: []),
let jsonDict = json as? [String: Any],
let exercisesDict = jsonDict["exercises"] as? [String: Any],
let conceptExercisesDict = exercisesDict["concept"] as? [[String: Any]],
let conceptExerciseSlugs = conceptExercisesDict.map({ $0["slug"] }) as? [String],
let practiceExercisesDict = exercisesDict["practice"] as? [[String: Any]],
let practiceExerciseSlugs = practiceExercisesDict.map({ $0["slug"] }) as? [String] {
conceptExercises += conceptExerciseSlugs
practiceExercises += practiceExerciseSlugs
} else {
print("Could not parse config.json at \(configPath)")
}

let conceptExerciseTargets: [Target] = conceptExercises.flatMap {
return [
.target(
name:"\($0.pascalCased)",
path:"./exercises/concept/\($0)/.meta/Sources"),
.testTarget(
name:"\($0.pascalCased)Tests",
dependencies: [
.target(name:"\($0.pascalCased)")
],
path:"./exercises/concept/\($0)/Tests",
exclude: ["LinuxMain.swift"])
]
}

let practiceExerciseTargets: [Target] = practiceExercises.flatMap {
return [
.target(
name:"\($0.pascalCased)",
path:"./exercises/practice/\($0)/.meta/Sources"),
.testTarget(
name:"\($0.pascalCased)Tests",
dependencies: [
.target(name:"\($0.pascalCased)")
],
path:"./exercises/practice/\($0)/Tests")
]
}

let allTargets = conceptExerciseTargets + practiceExerciseTargets

let package = Package(
name: "xswift",
products: [
.library(
name: "xswift",
targets: allTargets.filter { $0.type == .regular }.map { $0.name })
],
targets: allTargets
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Please see the [contributing guide](https://github.com/exercism/x-api/blob/maste

## Swift Track

We use Travis CI to automatically run all the unit tests on the code that is going to be checked in. In addition we also have [SwiftLint](https://github.com/realm/SwiftLint) set up to make sure that the code is consistent across all exercises. Please run `swiftlint autocorrect --format` on your code before submitting a PR. Check the travis file to see which version of swift we are testing against. Make sure all the tests pass locally using the swift package manager. Keep in mind that we support Linux so the tests need to also pass on linux on Travis.
We use Github Actions to automatically run all the unit tests on the code that is going to be checked in. In addition we also have [SwiftLint](https://github.com/realm/SwiftLint) set up to make sure that the code is consistent across all exercises. Please run `swiftlint autocorrect --format` on your code before submitting a PR. Make sure all the tests pass locally using the swift package manager. Keep in mind that we support Linux so the tests need to also pass on linux.
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"files": {
"solution": ["Sources/%{pascal_slug}/%{pascal_slug}.swift"],
"test": ["Tests/%{pascal_slug}Tests/%{pascal_slug}Tests.swift"],
"example": ["Sources/%{pascal_slug}/%{pascal_slug}Example.swift"],
"exemplar": [".meta/Exemplar.swift"]
"example": [".meta/Sources/%{pascal_slug}/%{pascal_slug}Example.swift"],
"exemplar": [".meta/Sources/%{pascal_slug}/%{pascal_slug}Exemplar.swift"]
},
"exercises": {
"concept": [
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/bomb-defuser/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Tests/BombDefuserTests/BombDefuserTests.swift"
],
"exemplar": [
".meta/Exemplar.swift"
".meta/Sources/BombDefuser/BombDefuserExemplar.swift"
]
},
"contributors": [],
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/custom-signs/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Tests/CustomSignsTests/CustomSignsTests.swift"
],
"exemplar": [
".meta/Exemplar.swift"
".meta/Sources/CustomSigns/CustomSignsExemplar.swift"
]
}
}
2 changes: 1 addition & 1 deletion exercises/concept/freelancer-rates/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Tests/FreelancerRatesTests/FreelancerRatesTests.swift"
],
"exemplar": [
".meta/Exemplar.swift"
".meta/Sources/FreelancerRates/FreelancerRatesExemplar.swift"
]
},
"forked_from": [
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/high-score-board/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Tests/HighScoreBoardTests/HighScoreBoardTests.swift"
],
"exemplar": [
".meta/Exemplar.swift"
".meta/Sources/HighScoreBoard/HighScoreBoardExemplar.swift"
]
},
"forked_from": [
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/lasagna-master/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Tests/LasagnaMasterTests/LasagnaMasterTests.swift"
],
"exemplar": [
".meta/Exemplar.swift"
".meta/Sources/LasagnaMaster/LasagnaMasterExemplar.swift"
]
}
}
2 changes: 1 addition & 1 deletion exercises/concept/lasagna/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Tests/LasagnaTests/LasagnaTests.swift"
],
"exemplar": [
".meta/Exemplar.swift"
".meta/Sources/Lasagna/LasagnaExemplar.swift"
]
},
"forked_from": [
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/log-lines/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Tests/LogLinesTests/LogLinesTests.swift"
],
"exemplar": [
".meta/Exemplar.swift"
".meta/Sources/LogLines/LogLinesExemplar.swift"
]
},
"forked_from": [
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/magician-in-training/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Tests/MagicianInTrainingTests/MagicianInTrainingTests.swift"
],
"exemplar": [
".meta/Exemplar.swift"
".meta/Sources/MagicianInTraining/MagicianInTrainingExemplar.swift"
]
},
"forked_from": [
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/master-mixologist/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Tests/MasterMixologistTests/MasterMixologistTests.swift"
],
"exemplar": [
".meta/Exemplar.swift"
".meta/Sources/MasterMixologist/MasterMixologistExemplar.swift"
]
}
}
2 changes: 1 addition & 1 deletion exercises/concept/pizza-slices/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Tests/PizzaSlicesTests/PizzaSlicesTests.swift"
],
"exemplar": [
".meta/Exemplar.swift"
".meta/Sources/PizzaSlices/PizzaSlicesExemplar.swift"
]
}
}
2 changes: 1 addition & 1 deletion exercises/concept/poetry-club/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Tests/PoetryClubTests/PoetryClubTests.swift"
],
"exemplar": [
".meta/Exemplar.swift"
".meta/Sources/PoetryClub/PoetryClubExemplar.swift"
]
},
"forked_from": [
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/santas-helper/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Tests/SantasHelperTests/SantasHelperTests.swift"
],
"exemplar": [
".meta/Exemplar.swift"
".meta/Sources/SantasHelper/SantasHelperExemplar.swift"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ final class SantasHelperTests: XCTestCase {
)
}
static var allTests = [
("testCartesianToPolar", testCaretesianToPolar),
("testCartesianToPolarQ3", testCaretesianToPolarQ3),
("testCartesianToPolar", testCartesianToPolar),
("testCartesianToPolarQ3", testCartesianToPolarQ3),
("testCombineRecords", testCombineRecords),
]
}
2 changes: 1 addition & 1 deletion exercises/concept/secret-agent/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Tests/SecretAgentTests/SecretAgentTests.swift"
],
"exemplar": [
".meta/Exemplar.swift"
".meta/Sources/SecretAgent/SecretAgentExemplar.swift"
]
}
}
2 changes: 1 addition & 1 deletion exercises/concept/vehicle-purchase/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Tests/VehiclePurchaseTests/VehiclePurchaseTests.swift"
],
"exemplar": [
".meta/Exemplar.swift"
".meta/Sources/VehiclePurchase/VehiclePurchaseExemplar.swift"
]
},
"contributors": [],
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/windowing-system/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Tests/WindowingSystemTests/WindowingSystemTests.swift"
],
"exemplar": [
".meta/Exemplar.swift"
".meta/Sources/WindowingSystem/WindowingSystemExemplar.swift"
]
}
}
5 changes: 0 additions & 5 deletions xswift-test-spm

This file was deleted.