Skip to content
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
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ import Synchronization

### Writing tests

Write all new tests with Swift Testing (`import Testing`, `@Test`, `#expect`, `#require`), including tests brought in from other branches or pull requests. Follow the existing suites: a `struct`, `@Test` functions named for the behaviour without a `test` prefix, and `@Test(arguments:)` instead of looping over inputs. Some older suites still use XCTest; when adding to one, a new Swift Testing suite is preferred over more XCTest cases.
All tests use Swift Testing (`import Testing`, `@Test`, `#expect`, `#require`); there is no XCTest, so convert tests brought in from other branches or pull requests. Each suite is an implicit one: a plain `struct` (a `class` only when a test needs `deinit`) holding `@Test` functions named for the behaviour without a `test` prefix, with no free-standing `@Test` functions. Use `@Suite` only to set a trait such as `.serialized` or `.timeLimit`, never just for a display name. Use `@Test(arguments:)` instead of looping over inputs or writing near-duplicate tests. Compare floating-point values with `#expect(a.isApproximately(b, tolerance: 0.001))` (`SwiftDraw/Tests/Utilities/FloatingPoint+Approximately.swift`).

Swift Testing runs tests in parallel. Give each test its own state (caches, temporary file names, renderers) rather than sharing globals, or mark the suite `@Suite(.serialized)` when it must touch global state such as the log sink. Tests that draw with AppKit or UIKit (`NSImage`, `UIImage`, views) need `@MainActor`.

## Checking rendering changes

Expand Down
1 change: 0 additions & 1 deletion DOM/Tests/Parser.XML.PathTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ private typealias Coordinate = DOM.Coordinate
private typealias Segment = DOM.Path.Segment
private typealias CoordinateSpace = DOM.Path.Segment.CoordinateSpace

@Suite("Parser XML Path Tests")
struct ParserXMLPathTests {

@Test
Expand Down
1 change: 0 additions & 1 deletion DOM/Tests/Parser.XML.PatternTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import Testing

private typealias Coordinate = DOM.Coordinate

@Suite("Parser XML Pattern Tests")
struct ParserXMLPatternTests {

@Test
Expand Down
1 change: 0 additions & 1 deletion DOM/Tests/Parser.XML.RadialGradientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import Foundation
import Testing
@testable import SwiftDrawDOM

@Suite("Parser XML Radial Gradient Tests")
struct ParserXMLRadialGradientTests {

@Test
Expand Down
1 change: 0 additions & 1 deletion DOM/Tests/Parser.XML.StyleSheetCascadeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import Testing
import Foundation
@testable import SwiftDrawDOM

@Suite("Parser XML StyleSheet Cascade Tests")
struct ParserXMLStyleSheetCascadeTests {

typealias Selector = DOM.StyleSheet.ComplexSelector
Expand Down
1 change: 0 additions & 1 deletion DOM/Tests/Parser.XML.StyleSheetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import Testing
@testable import SwiftDrawDOM

@Suite("Parser XML StyleSheet Tests")
struct ParserXMLStyleSheetTests {

@Test
Expand Down
1 change: 0 additions & 1 deletion DOM/Tests/Parser.XML.TextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import Testing
@testable import SwiftDrawDOM

@Suite("Parser XML Text Tests")
struct ParserXMLTextTests {

@Test
Expand Down
1 change: 0 additions & 1 deletion DOM/Tests/Parser.XML.TransformTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import Testing
@testable import SwiftDrawDOM

@Suite("Parser Transform Tests")
struct ParserTransformTests {

@Test
Expand Down
1 change: 0 additions & 1 deletion DOM/Tests/ParserSVGImageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import Testing
@testable import SwiftDrawDOM
import Foundation

@Suite("Parser SVG Image Tests")
struct ParserSVGImageTests {

@Test
Expand Down
1 change: 0 additions & 1 deletion DOM/Tests/StyleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import Testing
@testable import SwiftDrawDOM

@Suite("Style Tests")
struct StyleTests {

@Test
Expand Down
1 change: 0 additions & 1 deletion DOM/Tests/UseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import Testing
@testable import SwiftDrawDOM

@Suite("Use Tests")
struct UseTests {

@Test
Expand Down
1 change: 0 additions & 1 deletion DOM/Tests/ValueParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import Foundation
import Testing
@testable import SwiftDrawDOM

@Suite("Value Parser Tests")
struct ValueParserTests {

var parser = XMLParser.ValueParser()
Expand Down
1 change: 0 additions & 1 deletion DOM/Tests/XML.Parser.ScannerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public import Foundation
import Testing
@testable import SwiftDrawDOM

@Suite("Scanner Tests")
struct ScannerTests {

@Test
Expand Down
1 change: 0 additions & 1 deletion DOM/Tests/XML.SAXParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import Foundation
import Testing
@testable import SwiftDrawDOM

@Suite("SAX Parser Tests")
struct SAXParserTests {

@Test
Expand Down
91 changes: 44 additions & 47 deletions SwiftDraw/Tests/CommandLine/CommandLine.ArgumentsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,57 +29,54 @@
// 3. This notice may not be removed or altered from any source distribution.
//

import XCTest
import Testing
@testable import SwiftDraw

final class CommandLineArgumentsTests: XCTestCase {
struct CommandLineArgumentsTests {

func testParseModifiers() throws {
var modifiers = try CommandLine.parseModifiers(from: [
"--format", "some", "--output", "more", "--scale", "magnify", "--size", "huge",
])
XCTAssertEqual(modifiers, [.format: "some", .output: "more", .scale: "magnify", .size: "huge"])

modifiers = try CommandLine.parseModifiers(from: [
"--ultralightInsets", "a", "--blackInsets", "b", "--hideUnsupportedFilters", "--legacy",
])
XCTAssertEqual(
modifiers,
[.ultralightInsets: "a", .blackInsets: "b", .hideUnsupportedFilters: nil, .legacy: nil]
)

modifiers = try CommandLine.parseModifiers(from: [
"--ultralight-insets", "a", "--black-insets", "b", "--hide-unsupported-filters", "--legacy",
])
XCTAssertEqual(
modifiers,
[.ultralightInsets: "a", .blackInsets: "b", .hideUnsupportedFilters: nil, .legacy: nil]
)

modifiers = try CommandLine.parseModifiers(from: ["--format", "png", "--quiet"])
XCTAssertEqual(modifiers, [.format: "png", .quiet: nil])
}

func testParseModifiersThrowsForOddPairs() {
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format"]))
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "--output"]))
@Test(
arguments: [
(
["--format", "some", "--output", "more", "--scale", "magnify", "--size", "huge"],
[.format: "some", .output: "more", .scale: "magnify", .size: "huge"]
),
(
["--ultralightInsets", "a", "--blackInsets", "b", "--hideUnsupportedFilters", "--legacy"],
[.ultralightInsets: "a", .blackInsets: "b", .hideUnsupportedFilters: nil, .legacy: nil]
),
(
["--ultralight-insets", "a", "--black-insets", "b", "--hide-unsupported-filters", "--legacy"],
[.ultralightInsets: "a", .blackInsets: "b", .hideUnsupportedFilters: nil, .legacy: nil]
),
(
["--format", "png", "--quiet"],
[.format: "png", .quiet: nil]
),
] as [([String], [CommandLine.Modifier: String?])]
)
func parsesModifiers(args: [String], expected: [CommandLine.Modifier: String?]) throws {
#expect(try CommandLine.parseModifiers(from: args) == expected)
}

func testParseModifiersThrowsForDuplicateModifiers() {
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "--format", "jpg"]))
XCTAssertThrowsError(
try CommandLine.parseModifiers(from: ["--format", "png", "--output", "more", "--output", "evenmore"])
)
@Test(
arguments: [
// odd pairs
["--format"],
["--format", "png", "--output"],
// duplicate modifiers
["--format", "png", "--format", "jpg"],
["--format", "png", "--output", "more", "--output", "evenmore"],
// unknown modifiers
["--unknown", "png"],
["--format", "png", "--unknown", "more"],
// missing prefix
["format", "png"],
["--format", "png", "output", "more"],
]
)
func invalidModifiersThrow(args: [String]) {
#expect(throws: CommandLine.Error.invalid) {
try CommandLine.parseModifiers(from: args)
}
}

func testParseModifiersThrowsForUnknownModifiers() {
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--unknown", "png"]))
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "--unknown", "more"]))
}

func testParseModifiersThrowsForMissingPrefix() {
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["format", "png"]))
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "output", "more"]))
}

}
Loading
Loading