Skip to content

Commit

Permalink
Merge branch 'feature/FindMutansCommand'
Browse files Browse the repository at this point in the history
  • Loading branch information
SoriUR committed Aug 1, 2022
2 parents 8b791cb + 0bfe238 commit 7d71cab
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 1,966 deletions.
102 changes: 102 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/Mutanus.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "mutanus"
BuildableName = "mutanus"
BlueprintName = "mutanus"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "MutanusTests"
BuildableName = "MutanusTests"
BlueprintName = "MutanusTests"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "MutanusTests"
BuildableName = "MutanusTests"
BlueprintName = "MutanusTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "mutanus"
BuildableName = "mutanus"
BlueprintName = "mutanus"
ReferencedContainer = "container:">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "mutanus"
BuildableName = "mutanus"
BlueprintName = "mutanus"
ReferencedContainer = "container:">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
1,900 changes: 0 additions & 1,900 deletions Mutanus.xcodeproj/project.pbxproj

This file was deleted.

This file was deleted.

This file was deleted.

8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
"repositoryURL": "https://github.com/apple/swift-argument-parser",
"state": {
"branch": null,
"revision": "d2930e8fcf9c33162b9fcc1d522bc975e2d4179b",
"version": "1.0.1"
"revision": "df9ee6676cd5b3bf5b330ec7568a5644f547201b",
"version": "1.1.3"
}
},
{
"package": "SwiftSyntax",
"repositoryURL": "https://github.com/apple/swift-syntax.git",
"state": {
"branch": null,
"revision": "2fff9fc25cdc059379b6bd309377cfab45d8520c",
"version": "0.50400.0"
"revision": "0b6c22b97f8e9320bca62e82cdbee601cf37ad3f",
"version": "0.50600.1"
}
}
]
Expand Down
26 changes: 18 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
// swift-tools-version:5.4
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

#if swift(<5.5)
let swiftSyntaxVersion = Package.Dependency.Requirement.exact("0.50400.0")
var dependencies: [Target.Dependency] = [
.product(name: "SwiftSyntax", package: "SwiftSyntax"),
.product(name: "ArgumentParser", package: "ArgumentParser")
]

#if swift(>=5.6)
let swiftSyntaxVersion = Package.Dependency.Requirement.exact("0.50600.1")
dependencies.append(.product(name: "SwiftSyntaxParser", package: "SwiftSyntax"))
#elseif swift(>=5.5)
let swiftSyntaxVersion = Package.Dependency.Requirement.exactItem("0.50500.0")
let swiftSyntaxVersion = Package.Dependency.Requirement.exact("0.50500.0")
#else
let swiftSyntaxVersion = Package.Dependency.Requirement.exact("0.50400.0")
#endif

let package = Package(
name: "Mutanus",
platforms: [
.macOS(.v10_15)
],
products: [
.executable(name: "mutanus", targets: ["Mutanus"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
.package(name: "ArgumentParser", url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
.package(name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax.git", swiftSyntaxVersion),
],
targets: [
.executableTarget(
name: "Mutanus",
dependencies: [
"SwiftSyntax",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]),
dependencies: dependencies
),
.testTarget(
name: "MutanusTests",
dependencies: ["Mutanus"]),
Expand Down
2 changes: 1 addition & 1 deletion Sources/Mutanus/Commands/Mutanus+CreateConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension Mutanus {

private var fileManager: MutanusFileManger { CustomFileManager() }

@Option(name: .shortAndLong, help: "Path for configuration template to be created at")
@Argument(help: "Path for configuration template to be created at")
var path: String?

func run() throws {
Expand Down
33 changes: 3 additions & 30 deletions Sources/Mutanus/Commands/Mutanus+ExtractSources.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ArgumentParser
extension Mutanus {
final class ExtractSources: ParsableCommand, PathValidator, ConfigValidator {

static let configuration = CommandConfiguration(abstract: "Extracts sources for given configuration or ")
static let configuration = CommandConfiguration(abstract: "Extracts sources for given configuration")
var fileManager: MutanusFileManger { CustomFileManager() }

@Option(name: .shortAndLong, help: "Relative or absolute path to the configuration file")
Expand All @@ -23,39 +23,12 @@ extension Mutanus {
_ = try ExtractSourceFilesStep(
fileManager: fileManager,
configuration: configuration,
delegate: self
).perform(.testSucceeded)
delegate: nil
).executeStep(.testSucceeded)
}
}
}

extension Mutanus.ExtractSources : MutanusSequenceStepDelegate {
func stepStarted<T: ChainLink>(_ step: T) {
switch step {
case is ExtractSourceFilesStep:
Logger.logEvent(.sourceFilesStarted)
default:
break
}
}

func stepFinished<T: ChainLink>(_ step: T, result: T.Result) throws {

switch step {
case is ExtractSourceFilesStep:
try handleSourcesStepResult(result as! ExtractSourceFilesStep.Result)
default:
break
}
}

func handleSourcesStepResult(_ result: ExtractSourceFilesStep.Result) throws {
Logger.logEvent(.sourceFilesFinished(sources: result))

guard !result.isEmpty else { throw MutanusError.emptySources }
}
}

// MARK: - Validation
extension Mutanus.ExtractSources {
func validate() throws {
Expand Down
53 changes: 53 additions & 0 deletions Sources/Mutanus/Commands/Mutanus+FindMutants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Created by Iurii Sorokin on 08.03.2022.
//

import Foundation
import ArgumentParser

extension Mutanus {
final class FindMutants: ParsableCommand, PathValidator, ConfigValidator {

static let configuration = CommandConfiguration(abstract: "Find mutants for given configuration or file")
var fileManager: MutanusFileManger { CustomFileManager() }

@Option(name: .shortAndLong, help: "Relative or absolute path to the configuration file")
var configPath: String?

@Option(name: .shortAndLong, parsing: .upToNextOption, help: "Relative or absolute paths to files")
var files: [String] = []

func run() throws {

let filesTest: [String]

if let configPath = configPath {
let configuration = try validateConfig(atPath: configPath)

filesTest = try ExtractSourceFilesStep(
fileManager: fileManager,
configuration: configuration,
delegate: self
).executeStep(.testSucceeded)
} else {
filesTest = files
}

print(try FindMutantsStep().executeStep(filesTest))
}
}
}

// MARK: - Validation
extension Mutanus.FindMutants {
func validate() throws {

guard configPath != nil || !files.isEmpty else { throw ValidationError("asd") }

if let configPath = configPath {
self.configPath = try validatePath(configPath)
}

files = try files.map { try validatePath($0) }
}
}
2 changes: 1 addition & 1 deletion Sources/Mutanus/Protocols/PathValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ extension PathValidator {
return relativeConfigurationPath
}

throw ValidationError("Configuration file doesn't exits at given path")
throw ValidationError("File doesn't exits at: \(path)")
}
}
12 changes: 6 additions & 6 deletions Sources/Mutanus/Steps/FindMutantsStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

import Foundation
import SwiftSyntax
import SwiftSyntaxParser

final class FindMutantsStep: MutanusSequenceStep {

let reportCompiler: ReportCompiler
let reportCompiler: ReportCompiler?

init(
reportCompiler: ReportCompiler,
delegate: MutanusSequenceStepDelegate?
reportCompiler: ReportCompiler? = nil,
delegate: MutanusSequenceStepDelegate? = nil
) {
self.reportCompiler = reportCompiler
self.delegate = delegate
Expand Down Expand Up @@ -62,7 +63,7 @@ final class FindMutantsStep: MutanusSequenceStep {
maxFileCount: maxCount
)

reportCompiler.extractedSources(info)
reportCompiler?.extractedSources(info)

return info
}
Expand All @@ -82,8 +83,7 @@ final class FindMutantsStep: MutanusSequenceStep {
}

private func filePositionOrder(lhs: MutationPoint, rhs: MutationPoint) -> Bool {
return lhs.position.line < rhs.position.line &&
lhs.position.column < rhs.position.column
return lhs.position.line < rhs.position.line && lhs.position.column < rhs.position.column
}
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/Mutanus/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ struct Mutanus: ParsableCommand {
subcommands: [
Run.self,
CreateConfig.self,
ExtractSources.self
ExtractSources.self,
FindMutants.self
]
)
}
Expand Down

0 comments on commit 7d71cab

Please sign in to comment.