Skip to content

Commit e3dd379

Browse files
authored
Make use of concise literal paths everywhere (#302)
Both test suite and docs. We leave those in `PathTests` unchanged, since that file intentionally contains a mix of different concise and verbose paths for testing purposes, and we also leave a handful of examples of verbose paths in the docs to demonstrate it's possible. Otherwise everywhere uses the concise path syntax
1 parent 69cc8a3 commit e3dd379

12 files changed

+424
-409
lines changed

Readme.adoc

Lines changed: 168 additions & 153 deletions
Large diffs are not rendered by default.

os/test/src-jvm/ExampleTests.scala

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object ExampleTests extends TestSuite {
99
test("splash") - TestUtil.prep { wd =>
1010
if (Unix()) {
1111
// Make sure working directory exists and is empty
12-
val wd = os.pwd / "out" / "splash"
12+
val wd = os.pwd / "out/splash"
1313
os.remove.all(wd)
1414
os.makeDir.all(wd)
1515

@@ -95,8 +95,8 @@ object ExampleTests extends TestSuite {
9595

9696
// ignore multiline (second file) because its size varies
9797
largestThree.filterNot(_._2.last == "Multi Line.txt") ==> Seq(
98-
(711, wd / "misc" / "binary.png"),
99-
(22, wd / "folder1" / "one.txt")
98+
(711, wd / "misc/binary.png"),
99+
(22, wd / "folder1/one.txt")
100100
)
101101
}
102102

@@ -115,9 +115,9 @@ object ExampleTests extends TestSuite {
115115
}
116116
test("comparison") {
117117

118-
os.remove.all(os.pwd / "out" / "scratch" / "folder" / "thing" / "file")
118+
os.remove.all(os.pwd / "out/scratch/folder/thing/file")
119119
os.write(
120-
os.pwd / "out" / "scratch" / "folder" / "thing" / "file",
120+
os.pwd / "out/scratch/folder/thing/file",
121121
"Hello!",
122122
createFolders = true
123123
)
@@ -135,16 +135,16 @@ object ExampleTests extends TestSuite {
135135
}
136136
removeAll("out/scratch/folder/thing")
137137

138-
assert(os.list(os.pwd / "out" / "scratch" / "folder").toSeq == Nil)
138+
assert(os.list(os.pwd / "out/scratch/folder").toSeq == Nil)
139139

140140
os.write(
141-
os.pwd / "out" / "scratch" / "folder" / "thing" / "file",
141+
os.pwd / "out/scratch/folder/thing/file",
142142
"Hello!",
143143
createFolders = true
144144
)
145145

146-
os.remove.all(os.pwd / "out" / "scratch" / "folder" / "thing")
147-
assert(os.list(os.pwd / "out" / "scratch" / "folder").toSeq == Nil)
146+
os.remove.all(os.pwd / "out/scratch/folder/thing")
147+
assert(os.list(os.pwd / "out/scratch/folder").toSeq == Nil)
148148
}
149149

150150
test("constructingPaths") {
@@ -155,13 +155,13 @@ object ExampleTests extends TestSuite {
155155
val wd = os.pwd
156156

157157
// A path nested inside `wd`
158-
wd / "folder" / "file"
158+
wd / "folder/file"
159159

160160
// A path starting from the root
161-
os.root / "folder" / "file"
161+
os.root / "folder/file"
162162

163163
// A path with spaces or other special characters
164-
wd / "My Folder" / "My File.txt"
164+
wd / "My Folder/My File.txt"
165165

166166
// Up one level from the wd
167167
wd / os.up
@@ -171,17 +171,17 @@ object ExampleTests extends TestSuite {
171171
}
172172
test("newPath") {
173173

174-
val target = os.pwd / "out" / "scratch"
174+
val target = os.pwd / "out/scratch"
175175
}
176176
test("relPaths") {
177177

178178
// The path "folder/file"
179-
val rel1 = os.rel / "folder" / "file"
180-
val rel2 = os.rel / "folder" / "file"
179+
val rel1 = os.rel / "folder/file"
180+
val rel2 = os.rel / "folder/file"
181181

182182
// The relative difference between two paths
183-
val target = os.pwd / "out" / "scratch" / "file"
184-
assert((target relativeTo os.pwd) == os.rel / "out" / "scratch" / "file")
183+
val target = os.pwd / "out/scratch/file"
184+
assert((target relativeTo os.pwd) == os.rel / "out/scratch/file")
185185

186186
// `up`s get resolved automatically
187187
val minus = os.pwd relativeTo target
@@ -195,66 +195,66 @@ object ExampleTests extends TestSuite {
195195
test("subPaths") {
196196

197197
// The path "folder/file"
198-
val sub1 = os.sub / "folder" / "file"
199-
val sub2 = os.sub / "folder" / "file"
198+
val sub1 = os.sub / "folder/file"
199+
val sub2 = os.sub / "folder/file"
200200

201201
// The relative difference between two paths
202-
val target = os.pwd / "out" / "scratch" / "file"
203-
assert((target subRelativeTo os.pwd) == os.sub / "out" / "scratch" / "file")
202+
val target = os.pwd / "out/scratch/file"
203+
assert((target subRelativeTo os.pwd) == os.sub / "out/scratch/file")
204204

205205
// Converting os.RelPath to os.SubPath
206-
val rel3 = os.rel / "folder" / "file"
206+
val rel3 = os.rel / "folder/file"
207207
val sub3 = rel3.asSubPath
208208

209209
// `up`s are not allowed in sub paths
210210
intercept[Exception](os.pwd subRelativeTo target)
211211
}
212212
test("relSubPathEquality") {
213213
assert(
214-
(os.sub / "hello" / "world") == (os.rel / "hello" / "world"),
214+
(os.sub / "hello/world") == (os.rel / "hello/world"),
215215
os.sub == os.rel
216216
)
217217
}
218218
test("relPathCombine") {
219-
val target = os.pwd / "out" / "scratch" / "file"
219+
val target = os.pwd / "out/scratch/file"
220220
val rel = target relativeTo os.pwd
221-
val newBase = os.root / "code" / "server"
222-
assert(newBase / rel == os.root / "code" / "server" / "out" / "scratch" / "file")
221+
val newBase = os.root / "code/server"
222+
assert(newBase / rel == os.root / "code/server/out/scratch/file")
223223
}
224224
test("subPathCombine") {
225-
val target = os.pwd / "out" / "scratch" / "file"
225+
val target = os.pwd / "out/scratch/file"
226226
val sub = target subRelativeTo os.pwd
227-
val newBase = os.root / "code" / "server"
227+
val newBase = os.root / "code/server"
228228
assert(
229-
newBase / sub == os.root / "code" / "server" / "out" / "scratch" / "file",
230-
sub / sub == os.sub / "out" / "scratch" / "file" / "out" / "scratch" / "file"
229+
newBase / sub == os.root / "code/server/out/scratch/file",
230+
sub / sub == os.sub / "out/scratch/file/out/scratch/file"
231231
)
232232
}
233233
test("pathUp") {
234-
val target = os.root / "out" / "scratch" / "file"
235-
assert(target / os.up == os.root / "out" / "scratch")
234+
val target = os.root / "out/scratch/file"
235+
assert(target / os.up == os.root / "out/scratch")
236236
}
237237
test("relPathUp") {
238-
val target = os.rel / "out" / "scratch" / "file"
239-
assert(target / os.up == os.rel / "out" / "scratch")
238+
val target = os.rel / "out/scratch/file"
239+
assert(target / os.up == os.rel / "out/scratch")
240240
}
241241
test("relPathUp") {
242-
val target = os.sub / "out" / "scratch" / "file"
243-
assert(target / os.up == os.sub / "out" / "scratch")
242+
val target = os.sub / "out/scratch/file"
243+
assert(target / os.up == os.sub / "out/scratch")
244244
}
245245
test("canonical") {
246246
if (Unix()) {
247247

248-
assert((os.root / "folder" / "file" / os.up).toString == "/folder")
248+
assert((os.root / "folder/file" / os.up).toString == "/folder")
249249
// not "/folder/file/.."
250250

251-
assert((os.rel / "folder" / "file" / os.up).toString == "folder")
251+
assert((os.rel / "folder/file" / os.up).toString == "folder")
252252
// not "folder/file/.."
253253
}
254254
}
255255
test("findWc") {
256256

257-
val wd = os.pwd / "os" / "test" / "resources" / "test"
257+
val wd = os.pwd / "os/test/resources/test"
258258

259259
// find . -name '*.txt' | xargs wc -l
260260
val lines = os.walk(wd)

os/test/src-jvm/OpTestsJvmOnly.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,48 @@ import java.nio.charset.Charset
1010
object OpTestsJvmOnly extends TestSuite {
1111

1212
val tests = Tests {
13-
val res = os.pwd / "os" / "test" / "resources" / "test"
14-
val testFolder = os.pwd / "out" / "scratch" / "test"
13+
val res = os.pwd / "os/test/resources/test"
14+
val testFolder = os.pwd / "out/scratch/test"
1515
test("lsRecPermissions") {
1616
if (Unix()) {
17-
assert(os.walk(os.root / "var" / "run").nonEmpty)
17+
assert(os.walk(os.root / "var/run").nonEmpty)
1818
}
1919
}
2020
test("readResource") {
2121
test("positive") {
2222
test("absolute") {
23-
val contents = os.read(os.resource / "test" / "os" / "folder" / "file.txt")
23+
val contents = os.read(os.resource / "test/os/folder/file.txt")
2424
assert(contents.contains("file contents lols"))
2525

2626
val cl = getClass.getClassLoader
27-
val contents2 = os.read(os.resource(cl) / "test" / "os" / "folder" / "file.txt")
27+
val contents2 = os.read(os.resource(cl) / "test/os/folder/file.txt")
2828
assert(contents2.contains("file contents lols"))
2929
}
3030

3131
test("relative") {
3232
val cls = classOf[_root_.test.os.Testing]
33-
val contents = os.read(os.resource(cls) / "folder" / "file.txt")
33+
val contents = os.read(os.resource(cls) / "folder/file.txt")
3434
assert(contents.contains("file contents lols"))
3535

36-
val contents2 = os.read(os.resource(getClass) / "folder" / "file.txt")
36+
val contents2 = os.read(os.resource(getClass) / "folder/file.txt")
3737
assert(contents2.contains("file contents lols"))
3838
}
3939
}
4040
test("negative") {
4141
test - intercept[os.ResourceNotFoundException] {
42-
os.read(os.resource / "folder" / "file.txt")
42+
os.read(os.resource / "folder/file.txt")
4343
}
4444

4545
test - intercept[os.ResourceNotFoundException] {
4646
os.read(
47-
os.resource(classOf[_root_.test.os.Testing]) / "test" / "os" / "folder" / "file.txt"
47+
os.resource(classOf[_root_.test.os.Testing]) / "test/os/folder/file.txt"
4848
)
4949
}
5050
test - intercept[os.ResourceNotFoundException] {
51-
os.read(os.resource(getClass) / "test" / "os" / "folder" / "file.txt")
51+
os.read(os.resource(getClass) / "test/os/folder/file.txt")
5252
}
5353
test - intercept[os.ResourceNotFoundException] {
54-
os.read(os.resource(getClass.getClassLoader) / "folder" / "file.txt")
54+
os.read(os.resource(getClass.getClassLoader) / "folder/file.txt")
5555
}
5656
}
5757
}
@@ -74,16 +74,16 @@ object OpTestsJvmOnly extends TestSuite {
7474
// Not sure why this doesn't work on native
7575
test("redirectSubprocessInheritedOutput") {
7676
if (Unix()) { // relies on bash scripts that don't run on windows
77-
val scriptFolder = os.pwd / "os" / "test" / "resources" / "test"
77+
val scriptFolder = os.pwd / "os/test/resources/test"
7878
val lines = collection.mutable.Buffer.empty[String]
7979
os.Inherit.out.withValue(os.ProcessOutput.Readlines(lines.append(_))) {
8080
// Redirected
81-
os.proc(scriptFolder / "misc" / "echo_with_wd", "HELLO\nWorld").call(
81+
os.proc(scriptFolder / "misc/echo_with_wd", "HELLO\nWorld").call(
8282
cwd = os.root / "usr",
8383
stdout = os.Inherit
8484
)
8585
// Not Redirected
86-
os.proc(scriptFolder / "misc" / "echo_with_wd", "hello\nWORLD").call(
86+
os.proc(scriptFolder / "misc/echo_with_wd", "hello\nWORLD").call(
8787
cwd = os.root / "usr",
8888
stdout = os.InheritRaw
8989
)

0 commit comments

Comments
 (0)