|
| 1 | +import Foundation |
| 2 | +import Testing |
| 3 | +@testable import Cadova |
| 4 | + |
| 5 | +struct ProjectCommandLineFilterTests { |
| 6 | + init() { |
| 7 | + Platform.revealingFilesDisabled = true |
| 8 | + } |
| 9 | + |
| 10 | + @Test func `Project applies model filter from --model command line argument`() async throws { |
| 11 | + let tempDir = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString) |
| 12 | + try FileManager.default.createDirectory(at: tempDir, withIntermediateDirectories: true) |
| 13 | + defer { try? FileManager.default.removeItem(at: tempDir) } |
| 14 | + |
| 15 | + await CommandLineArguments.$overriddenArguments.withValue(["CadovaTests", "--model", "Differential"]) { |
| 16 | + await Project(root: tempDir) { |
| 17 | + await Model("Differential") { |
| 18 | + Box(10) |
| 19 | + } |
| 20 | + |
| 21 | + await Model("Other") { |
| 22 | + Sphere(diameter: 10) |
| 23 | + } |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + #expect(FileManager.default.fileExists(atPath: tempDir.appending(path: "Differential.3mf").path)) |
| 28 | + #expect(!FileManager.default.fileExists(atPath: tempDir.appending(path: "Other.3mf").path)) |
| 29 | + } |
| 30 | + |
| 31 | + @Test func `Project applies repeated --model=value command line arguments`() async throws { |
| 32 | + let tempDir = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString) |
| 33 | + try FileManager.default.createDirectory(at: tempDir, withIntermediateDirectories: true) |
| 34 | + defer { try? FileManager.default.removeItem(at: tempDir) } |
| 35 | + |
| 36 | + await CommandLineArguments.$overriddenArguments.withValue([ |
| 37 | + "CadovaTests", |
| 38 | + "--model=Standalone", |
| 39 | + "--model=GroupName/Differential" |
| 40 | + ]) { |
| 41 | + await Project(root: tempDir) { |
| 42 | + await Model("Standalone") { |
| 43 | + Box(10) |
| 44 | + } |
| 45 | + |
| 46 | + await Model("Ignored") { |
| 47 | + Sphere(diameter: 10) |
| 48 | + } |
| 49 | + |
| 50 | + await Group("GroupName") { |
| 51 | + await Model("Differential") { |
| 52 | + Cylinder(diameter: 5, height: 10) |
| 53 | + } |
| 54 | + |
| 55 | + await Model("Other") { |
| 56 | + Circle(diameter: 10) |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + #expect(FileManager.default.fileExists(atPath: tempDir.appending(path: "Standalone.3mf").path)) |
| 63 | + #expect(!FileManager.default.fileExists(atPath: tempDir.appending(path: "Ignored.3mf").path)) |
| 64 | + #expect(FileManager.default.fileExists(atPath: tempDir.appending(path: "GroupName/Differential.3mf").path)) |
| 65 | + #expect(!FileManager.default.fileExists(atPath: tempDir.appending(path: "GroupName/Other.3mf").path)) |
| 66 | + } |
| 67 | + |
| 68 | + @Test func `Project applies mixed --model NAME and --model=NAME command line arguments`() async throws { |
| 69 | + let tempDir = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString) |
| 70 | + try FileManager.default.createDirectory(at: tempDir, withIntermediateDirectories: true) |
| 71 | + defer { try? FileManager.default.removeItem(at: tempDir) } |
| 72 | + |
| 73 | + await CommandLineArguments.$overriddenArguments.withValue([ |
| 74 | + "CadovaTests", |
| 75 | + "--model", "Standalone", |
| 76 | + "--model=GroupName/Differential" |
| 77 | + ]) { |
| 78 | + await Project(root: tempDir) { |
| 79 | + await Model("Standalone") { |
| 80 | + Box(10) |
| 81 | + } |
| 82 | + |
| 83 | + await Model("Ignored") { |
| 84 | + Sphere(diameter: 10) |
| 85 | + } |
| 86 | + |
| 87 | + await Group("GroupName") { |
| 88 | + await Model("Differential") { |
| 89 | + Cylinder(diameter: 5, height: 10) |
| 90 | + } |
| 91 | + |
| 92 | + await Model("Other") { |
| 93 | + Circle(diameter: 10) |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + #expect(FileManager.default.fileExists(atPath: tempDir.appending(path: "Standalone.3mf").path)) |
| 100 | + #expect(!FileManager.default.fileExists(atPath: tempDir.appending(path: "Ignored.3mf").path)) |
| 101 | + #expect(FileManager.default.fileExists(atPath: tempDir.appending(path: "GroupName/Differential.3mf").path)) |
| 102 | + #expect(!FileManager.default.fileExists(atPath: tempDir.appending(path: "GroupName/Other.3mf").path)) |
| 103 | + } |
| 104 | +} |
0 commit comments