11use std:: fs:: File ;
2- use std:: io:: { Write , Read , BufRead } ;
2+ use std:: io:: { Read , Write } ;
33use std:: path:: { Path , PathBuf } ;
44
55use codeql_extractor:: extractor:: simple;
66use flate2:: read:: GzDecoder ;
77use tree_sitter_ql;
88
9-
10-
119/// An very simple happy-path test.
1210/// We run the extractor using the tree-sitter-ql grammar and a single source file,
1311/// and check that we get a reasonable-looking trap file in the expected location.
@@ -30,14 +28,16 @@ fn simple_extractor() {
3028 let foo_qll = {
3129 let path = source_archive_dir. join ( "foo.qll" ) ;
3230 let mut file = File :: create ( & path) . expect ( "Failed to create src/foo.qll" ) ;
33- file. write_all ( b"predicate p(int a) { a = 1 }" ) . expect ( "Failed to write to foo.qll" ) ;
31+ file. write_all ( b"predicate p(int a) { a = 1 }" )
32+ . expect ( "Failed to write to foo.qll" ) ;
3433 PathBuf :: from ( path)
3534 } ;
3635
3736 let file_list = {
3837 let path = root_dir. join ( "files.txt" ) ;
3938 let mut file = File :: create ( & path) . expect ( "Failed to create files.txt" ) ;
40- file. write_all ( foo_qll. as_path ( ) . display ( ) . to_string ( ) . as_bytes ( ) ) . expect ( "Failed to write to files.txt" ) ;
39+ file. write_all ( foo_qll. as_path ( ) . display ( ) . to_string ( ) . as_bytes ( ) )
40+ . expect ( "Failed to write to files.txt" ) ;
4141 path
4242 } ;
4343
@@ -54,14 +54,20 @@ fn simple_extractor() {
5454
5555 // Check for the presence of $root/trap/$root/src/foo.qll
5656 {
57- let root_dir_relative = {
57+ let root_dir_relative = {
5858 let r = root_dir. as_path ( ) . display ( ) . to_string ( ) ;
5959 r. strip_prefix ( "/" ) . unwrap ( ) . to_string ( )
6060 } ;
61- let foo_qll_trap_gz = root_dir. join ( "trap" ) . join ( root_dir_relative) . join ( "src/foo.qll.trap.gz" ) ;
62- let mut decoder = GzDecoder :: new ( File :: open ( foo_qll_trap_gz) . expect ( "Failed to open foo.qll.trap.gz" ) ) ;
61+ let foo_qll_trap_gz = root_dir
62+ . join ( "trap" )
63+ . join ( root_dir_relative)
64+ . join ( "src/foo.qll.trap.gz" ) ;
65+ let mut decoder =
66+ GzDecoder :: new ( File :: open ( foo_qll_trap_gz) . expect ( "Failed to open foo.qll.trap.gz" ) ) ;
6367 let mut first_line = [ 0 ; 31 ] ;
64- decoder. read_exact ( & mut first_line) . expect ( "Failed to read from foo.qll.trap.gz" ) ;
68+ decoder
69+ . read_exact ( & mut first_line)
70+ . expect ( "Failed to read from foo.qll.trap.gz" ) ;
6571 assert_eq ! ( first_line. as_slice( ) , b"// Auto-generated TRAP file for" ) ;
6672 }
6773}
@@ -70,4 +76,4 @@ fn create_dir(root: &Path, path: impl AsRef<Path>) -> PathBuf {
7076 let full_path = root. join ( path) ;
7177 std:: fs:: create_dir_all ( & full_path) . expect ( "Failed to create directory" ) ;
7278 full_path. into ( )
73- }
79+ }
0 commit comments