-
-
Notifications
You must be signed in to change notification settings - Fork 160
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
ErikSchierboom
merged 5 commits into
exercism:main
from
sanderploegsma:feature/concept-exercises-ci
Sep 30, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
24aaa7a
Move exemplar implementations in concept exercises
sanderploegsma 71612fe
Test both concept and practice exercises in CI
sanderploegsma 8ad3420
Update README to remove references to Travis CI
sanderploegsma 7e438bc
Move concept exemplar sources to `.meta/Sources`
sanderploegsma 159ed57
Update default path to practice example source
sanderploegsma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.