Skip to content

Commit baabe66

Browse files
committed
Ruby: update Files.ql tests for write accesses
1 parent 12ce3d4 commit baabe66

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

ruby/ql/test/library-tests/frameworks/files/Files.expected

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fileInstances
2-
| Files.rb:2:1:2:30 | ... = ... |
3-
| Files.rb:2:1:2:30 | ... = ... |
4-
| Files.rb:2:12:2:30 | call to new |
2+
| Files.rb:2:1:2:36 | ... = ... |
3+
| Files.rb:2:1:2:36 | ... = ... |
4+
| Files.rb:2:12:2:36 | call to new |
55
| Files.rb:3:1:3:21 | ... = ... |
66
| Files.rb:3:1:3:21 | ... = ... |
77
| Files.rb:3:14:3:21 | foo_file |
@@ -15,10 +15,12 @@ fileInstances
1515
| Files.rb:24:19:24:40 | call to open |
1616
| Files.rb:37:1:37:33 | ... = ... |
1717
| Files.rb:37:14:37:33 | call to open |
18+
| Files.rb:40:1:40:8 | foo_file |
19+
| Files.rb:41:1:41:26 | call to open |
1820
ioInstances
19-
| Files.rb:2:1:2:30 | ... = ... |
20-
| Files.rb:2:1:2:30 | ... = ... |
21-
| Files.rb:2:12:2:30 | call to new |
21+
| Files.rb:2:1:2:36 | ... = ... |
22+
| Files.rb:2:1:2:36 | ... = ... |
23+
| Files.rb:2:12:2:36 | call to new |
2224
| Files.rb:3:1:3:21 | ... = ... |
2325
| Files.rb:3:1:3:21 | ... = ... |
2426
| Files.rb:3:14:3:21 | foo_file |
@@ -40,6 +42,12 @@ ioInstances
4042
| Files.rb:35:13:35:56 | call to open |
4143
| Files.rb:37:1:37:33 | ... = ... |
4244
| Files.rb:37:14:37:33 | call to open |
45+
| Files.rb:40:1:40:8 | foo_file |
46+
| Files.rb:41:1:41:26 | call to open |
47+
| Files.rb:44:1:44:45 | ... = ... |
48+
| Files.rb:44:1:44:45 | ... = ... |
49+
| Files.rb:44:11:44:45 | call to open |
50+
| Files.rb:48:1:48:7 | io_file |
4351
fileModuleReaders
4452
| Files.rb:7:13:7:32 | call to readlines |
4553
ioReaders
@@ -64,7 +72,21 @@ fileSystemAccesses
6472
| Files.rb:20:13:20:25 | call to read |
6573
| Files.rb:29:12:29:29 | call to read |
6674
| Files.rb:37:14:37:33 | call to open |
75+
| Files.rb:40:1:40:22 | call to puts |
76+
| Files.rb:41:1:41:26 | call to open |
77+
| Files.rb:41:1:41:43 | call to write |
78+
| Files.rb:48:1:48:40 | call to printf |
6779
fileNameSources
6880
| Files.rb:10:6:10:18 | call to path |
6981
| Files.rb:11:6:11:21 | call to to_path |
7082
| Files.rb:14:8:14:43 | call to makedirs |
83+
ioWriters
84+
| Files.rb:48:1:48:40 | call to printf |
85+
fileWriters
86+
| Files.rb:40:1:40:22 | call to puts |
87+
| Files.rb:41:1:41:43 | call to write |
88+
| Files.rb:48:1:48:40 | call to printf |
89+
fileSystemWriteAccesses
90+
| Files.rb:40:1:40:22 | call to puts |
91+
| Files.rb:41:1:41:43 | call to write |
92+
| Files.rb:48:1:48:40 | call to printf |

ruby/ql/test/library-tests/frameworks/files/Files.ql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ query predicate fileSystemReadAccesses(FileSystemReadAccess a) { any() }
2121
query predicate fileSystemAccesses(FileSystemAccess a) { any() }
2222

2323
query predicate fileNameSources(FileNameSource s) { any() }
24+
25+
query predicate ioWriters(IO::IOWriter r) { any() }
26+
27+
query predicate fileWriters(IO::FileWriter r) { any() }
28+
29+
query predicate fileSystemWriteAccesses(FileSystemWriteAccess a) { any() }

ruby/ql/test/library-tests/frameworks/files/Files.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# `foo_file` is a `File` instance
2-
foo_file = File.new("foo.txt")
2+
foo_file = File.new("foo.txt", "a+")
33
foo_file_2 = foo_file
44
foo_file
55

@@ -34,4 +34,15 @@
3434
# `rand_open` is an `IO` instance
3535
rand_open = IO.open(IO.sysopen("/dev/random", "r"), "r")
3636

37-
foo_file_3 = File.open("foo.txt")
37+
foo_file_3 = File.open("foo.txt")
38+
39+
# File write accesses
40+
foo_file.puts("hello")
41+
File.open("foo.txt", "a+").write("world\n")
42+
43+
# IO instance
44+
io_file = IO.open(IO.sysopen("foo.txt", "w"))
45+
str_1 = "hello"
46+
int_1 = 123
47+
# File/IO write
48+
io_file.printf("%s: %d\n", str_1, int_1)

0 commit comments

Comments
 (0)