Skip to content

Commit 70c2be8

Browse files
committed
Files library tests
1 parent 05a04f4 commit 70c2be8

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
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 |
5+
| Files.rb:3:1:3:21 | ... = ... |
6+
| Files.rb:3:1:3:21 | ... = ... |
7+
| Files.rb:3:14:3:21 | foo_file |
8+
| Files.rb:4:1:4:8 | foo_file |
9+
| Files.rb:7:13:7:22 | foo_file_2 |
10+
| Files.rb:10:6:10:13 | foo_file |
11+
| Files.rb:11:6:11:13 | foo_file |
12+
| Files.rb:23:1:23:33 | ... = ... |
13+
| Files.rb:23:19:23:33 | call to open |
14+
| Files.rb:24:1:24:40 | ... = ... |
15+
| Files.rb:24:19:24:40 | call to open |
16+
ioInstances
17+
| Files.rb:2:1:2:30 | ... = ... |
18+
| Files.rb:2:1:2:30 | ... = ... |
19+
| Files.rb:2:12:2:30 | call to new |
20+
| Files.rb:3:1:3:21 | ... = ... |
21+
| Files.rb:3:1:3:21 | ... = ... |
22+
| Files.rb:3:14:3:21 | foo_file |
23+
| Files.rb:4:1:4:8 | foo_file |
24+
| Files.rb:7:13:7:22 | foo_file_2 |
25+
| Files.rb:10:6:10:13 | foo_file |
26+
| Files.rb:11:6:11:13 | foo_file |
27+
| Files.rb:17:1:17:50 | ... = ... |
28+
| Files.rb:17:1:17:50 | ... = ... |
29+
| Files.rb:17:8:17:50 | call to new |
30+
| Files.rb:18:1:18:13 | ... = ... |
31+
| Files.rb:18:10:18:13 | rand |
32+
| Files.rb:20:13:20:16 | rand |
33+
| Files.rb:23:1:23:33 | ... = ... |
34+
| Files.rb:23:19:23:33 | call to open |
35+
| Files.rb:24:1:24:40 | ... = ... |
36+
| Files.rb:24:19:24:40 | call to open |
37+
fileReaders
38+
| Files.rb:7:13:7:32 | call to readlines |
39+
ioReaders
40+
| Files.rb:7:13:7:32 | call to readlines | File |
41+
| Files.rb:20:13:20:25 | call to read | IO |
42+
| Files.rb:29:12:29:29 | call to read | IO |
43+
| Files.rb:32:8:32:23 | call to read | IO |
44+
ioFileReaders
45+
| Files.rb:7:13:7:32 | call to readlines | File |
46+
| Files.rb:29:12:29:29 | call to read | IO |
47+
fileModuleFilenameSources
48+
| Files.rb:10:6:10:18 | call to path |
49+
| Files.rb:11:6:11:21 | call to to_path |
50+
fileUtilsFilenameSources
51+
| Files.rb:14:8:14:43 | call to makedirs |
52+
fileSystemReadAccesses
53+
| Files.rb:7:13:7:32 | call to readlines |
54+
| Files.rb:29:12:29:29 | call to read |
55+
fileNameSources
56+
| Files.rb:10:6:10:18 | call to path |
57+
| Files.rb:11:6:11:21 | call to to_path |
58+
| Files.rb:14:8:14:43 | call to makedirs |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
private import ruby
2+
private import codeql.ruby.frameworks.Files
3+
private import codeql.ruby.Concepts
4+
5+
query predicate fileInstances(File::FileInstance i) { any() }
6+
7+
query predicate ioInstances(IO::IOInstance i) { any() }
8+
9+
query predicate fileReaders(File::FileModuleReader r) { any() }
10+
11+
query predicate ioReaders(IO::IOReader r, string api) { api = r.getAPI() }
12+
13+
query predicate ioFileReaders(IO::IOFileReader r, string api) { api = r.getAPI() }
14+
15+
query predicate fileModuleFilenameSources(File::FileModuleFilenameSource s) { any() }
16+
17+
query predicate fileUtilsFilenameSources(FileUtils::FileUtilsFilenameSource s) { any() }
18+
19+
query predicate fileSystemReadAccesses(FileSystemReadAccess a) { any() }
20+
21+
query predicate fileNameSources(FileNameSource s) { any() }
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# `foo_file` is a `File` instance
2+
foo_file = File.new("foo.txt")
3+
foo_file_2 = foo_file
4+
foo_file
5+
6+
# File read access
7+
foo_lines = foo_file_2.readlines
8+
9+
# `fp` is a file path
10+
fp = foo_file.path
11+
fp = foo_file.to_path
12+
13+
# `FileUtils.makedirs` returns an array of file names
14+
dirs = FileUtils.makedirs(["dir1", "dir2"])
15+
16+
# `rand` is an `IO` instance
17+
rand = IO.new(IO.sysopen("/dev/random", "r"), "r")
18+
rand_2 = rand
19+
20+
rand_data = rand.read(32)
21+
22+
# `foo_file_kernel` is a `File` instance
23+
foo_file_kernel = open("foo.txt")
24+
foo_file_kernel = Kernel.open("foo.txt")
25+
26+
foo_command_kernel = open("|ls")
27+
28+
# `IO.read("foo.txt")` reads from a file
29+
foo_text = IO.read("foo.txt")
30+
31+
# `IO.read("|date")` does not read from a file
32+
date = IO.read("|date")

0 commit comments

Comments
 (0)