@@ -6,6 +6,7 @@ import ch.tutteli.atrium.api.fluent.en_GB.isDirectory
66import ch.tutteli.atrium.api.fluent.en_GB.isReadable
77import ch.tutteli.atrium.api.fluent.en_GB.isRegularFile
88import ch.tutteli.atrium.api.fluent.en_GB.isWritable
9+ import ch.tutteli.atrium.api.fluent.en_GB.matches
910import ch.tutteli.atrium.api.fluent.en_GB.messageContains
1011import ch.tutteli.atrium.api.fluent.en_GB.notToBe
1112import ch.tutteli.atrium.api.fluent.en_GB.notToThrow
@@ -161,6 +162,39 @@ object DefaultTestFilesSpec: Spek({
161162 }
162163 }
163164
165+ describe("file name checks") {
166+ it("rejects file names that match the group directory pattern") {
167+ testFiles.beforeExecuteTest(mockScope<TestScopeImpl >("rejects bad file names"))
168+
169+ expect { testFiles.createFile("[test") }.notToThrow()
170+ expect { testFiles.createFile("test]") }.notToThrow()
171+ expect { testFiles.createFile("[test]") }.toThrow<IllegalArgumentException > {
172+ messageContains("[test]")
173+ }
174+ }
175+
176+ it("rejects directory names that match the group directory pattern") {
177+ testFiles.beforeExecuteTest(mockScope<TestScopeImpl >("rejects bad directory names"))
178+
179+ expect { testFiles.createDirectory("[test") }.notToThrow()
180+ expect { testFiles.createDirectory("test]") }.notToThrow()
181+ expect { testFiles.createDirectory("[test]") }.toThrow<IllegalArgumentException > {
182+ messageContains("[test]")
183+ }
184+ }
185+
186+ listOf('/', '\\', '<', '>', ':', '\"', '|', '? ', '*', '\u0000').forEach { badCharacter ->
187+ it("escapes '$badCharacter' if necessary") {
188+ testFiles.beforeExecuteTest(mockScope<TestScopeImpl >("test with -$badCharacter- in it"))
189+
190+ expect { testFiles.createFile("test") }.notToThrow {
191+ // check that / \ is not messing up the directory structure
192+ parent.fileName.matches(Regex (".test with -[^-]- in it."))
193+ }
194+ }
195+ }
196+ }
197+
164198 describe("file creation") {
165199 it("creates an empty file with the provided name") {
166200 val mockGroup = mockScope<GroupScopeImpl >("named file creation group")
@@ -214,26 +248,6 @@ object DefaultTestFilesSpec: Spek({
214248 }
215249 }
216250
217- it("rejects file names that match the group directory pattern") {
218- testFiles.beforeExecuteTest(mockScope<TestScopeImpl >("rejects bad file names"))
219-
220- expect { testFiles.createFile("[test") }.notToThrow()
221- expect { testFiles.createFile("test]") }.notToThrow()
222- expect { testFiles.createFile("[test]") }.toThrow<IllegalArgumentException > {
223- messageContains("[test]")
224- }
225- }
226-
227- it("rejects directory names that match the group directory pattern") {
228- testFiles.beforeExecuteTest(mockScope<TestScopeImpl >("rejects bad directory names"))
229-
230- expect { testFiles.createDirectory("[test") }.notToThrow()
231- expect { testFiles.createDirectory("test]") }.notToThrow()
232- expect { testFiles.createDirectory("[test]") }.toThrow<IllegalArgumentException > {
233- messageContains("[test]")
234- }
235- }
236-
237251 it("hands out absolute paths") {
238252 testFiles.beforeExecuteTest(mockScope<TestScopeImpl >("hands out absolute paths"))
239253
0 commit comments