Permalink
Browse files

no more log spew in 'make test' !!

  • Loading branch information...
1 parent 1364407 commit db814965655875e777e8d31a2121da82e5f12aac @aryx aryx committed Dec 2, 2011
View
@@ -664,7 +664,7 @@ visual:
-with_info DB_LIGHT.marshall -with_layers . -ocaml_filter .
tests:
- ./pfff_test all
+ ./pfff_test -verbose all
test: tests
push:
git push origin master
@@ -75,7 +75,9 @@ let unittest =
let env = Env_php.mk_env ~php_root:"/" in
(* run the bugs finders *)
- test_files +> List.iter (Check_all_php.check_file ~find_entity env);
+ Common.save_excursion Flag_analyze_php.verbose_checking false (fun()->
+ test_files +> List.iter (Check_all_php.check_file ~find_entity env)
+ );
if verbose then begin
!Error_php._errors +> List.iter (fun e ->
@@ -557,7 +557,7 @@ let static_method_callees_of_any any =
| Self _ | Parent _ ->
failwith "use Unsugar_php.unsugar_self_parent"
| LateStatic _ ->
- pr2 "LateStatic";
+ (* pr2 "LateStatic"; *)
None
in
sclass_opt +> Common.do_option (fun sclass ->
@@ -165,7 +165,7 @@ let index_db1_2 db files =
| Parse_php.Parse_error _
->
(* Backtrace.print (); *)
- pr2_err ("PB: BIG PBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB: " ^ file);
+ pr2 ("PB: BIG PBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB: " ^ file);
pr2 ("Undoing addition");
db +> add_filename_and_topids(file, []);
!all_ids +> List.iter (fun id ->
@@ -705,11 +705,14 @@ let db_of_files_or_dirs ?(annotate_variables_program=None) files_or_dirs =
* project base. Here we want to analyze a set of adhoc files or multiple
* dirs so there is no base so we use /
*)
+ Common.save_excursion Flag.verbose_database false (fun () ->
create_db
~db_support:Database_php.Mem
~files:(Some php_files)
~annotate_variables_program
+ ~verbose_stats:false
(Database_php.Project ("/", None))
+ )
(*****************************************************************************)
(* Main entry for Arg *)
@@ -20,6 +20,8 @@ open Database_php
module Db = Database_php
module DbH = Database_php_build_helpers
+open Database_php_build_helpers
+
(*****************************************************************************)
(* Helpers ast and tokens *)
(*****************************************************************************)
@@ -54,7 +56,7 @@ let index_db_includes_requires2
in
let msg = "ANALYZE_INCLUDE_REQUIRE" in
DbH.iter_files db (fun ((file, topids), i, total) ->
- Common.pr2 (spf "%s: %s %d/%d " msg file i total);
+ pr2 (spf "%s: %s %d/%d " msg file i total);
let program = topids +> List.map (fun id -> db.defs.toplevels#assoc id) in
let increq = Include_require_php.top_increq_of_program program in
@@ -68,7 +70,7 @@ let index_db_includes_requires2
match path_opt with
| Some path -> Some path
| None ->
- pr ("Bad include, can not statically determine the path");
+ pr2 ("Bad include, can not statically determine the path");
Lib_parsing_php.print_match ~format:Lib_parsing_php.Emacs [tok];
None
)
@@ -318,7 +318,7 @@ let add_defs_and_uses id kind ast pr db =
(*****************************************************************************)
(* todo? could avoid going through database_php.ml and parse directly? *)
-let gen_prolog_db db file =
+let gen_prolog_db ?(show_progress=true) db file =
Common.with_open_outfile file (fun (pr, _chan) ->
let pr s = pr (s ^ "\n") in
pr ("%% -*- prolog -*-");
@@ -340,8 +340,8 @@ let gen_prolog_db db file =
);
db.Db.defs.Db.id_kind#tolist
- +> (fun xs -> Common_extra.execute_and_show_progress2 (List.length xs)
- (fun k -> xs +> List.iter (fun (id, kind) ->
+ +> Common_extra.with_progress_list_metter ~show_progress (fun k xs ->
+ xs +> List.iter (fun (id, kind) ->
k();
pr (spf "kind(%s, %s)." (name_id id db) (string_of_id_kind kind));
pr (spf "at(%s, '%s', %d)."
@@ -357,7 +357,7 @@ let gen_prolog_db db file =
let ast = Db.ast_of_id id db in
add_defs_and_uses id kind ast pr db;
- ));
+ );
);
db.Db.uses.Db.includees_of_file#tolist +> List.iter (fun (file1, xs) ->
let file1 = Db.absolute_to_readable_filename file1 db in
@@ -1,3 +1,4 @@
-val gen_prolog_db:
+val gen_prolog_db:
+ ?show_progress:bool ->
Database_php.database -> Common.filename -> unit
@@ -98,11 +98,16 @@ let database_unittest =
);
"accept files with parse error" >:: (fun () ->
let data_dir = Config.path ^ "/tests/php/parsing_errors/" in
+ Common.save_excursion Flag_parsing_php.verbose_lexing false (fun () ->
+ Common.save_excursion Flag_parsing_php.verbose_parsing false (fun () ->
+ Common.save_excursion Common.verbose_level 0 (fun () ->
let _db = Database_php_build.db_of_files_or_dirs [data_dir] in
()
+ )))
);
]
+
(*---------------------------------------------------------------------------*)
(* Functions use/def, callgraph *)
(*---------------------------------------------------------------------------*)
@@ -146,143 +151,13 @@ let callgraph_unittest =
assert_equal [] (callees (id "z"));
assert_raises Not_found (fun () -> id "w");
);
-
- (* Checking the semantic of static method calls. *)
- "simple static method call" >:: (fun () ->
- let file = "
- class A { static function a() { } }
- function b() { A::a(); }
- "
- in
- let db = db_from_string file in
- (* shortcuts *)
- let id s = id s db in
- let callers id = callers id db in let callees id = callees id db in
- assert_equal [id "A::a"] (callees (id "b"));
- assert_equal [id "b"] (callers (id "A::a"));
- );
-
- "static method call with self:: and parent::" >:: (fun () ->
- let file = "
- class A {
- static function a() { }
- static function a2() { self::a(); }
- }
- class B extends A {
- function b() { parent::a(); }
- }
- "
- in
- let db = db_from_string file in
- (* shortcuts *)
- let id s = id s db in
- let callers id = callers id db in let _callees id = callees id db in
- assert_equal
- (sort [id "A::a2"; id "B::b";
- (* todo? we now consider the class as callers too *)
- id "A::"; id "B::"])
- (sort (callers (id "A::a")));
- );
-
- (* In PHP it is ok to call B::foo() even if B does not define
- * a static method 'foo' provided that B inherits from a class
- * that defines such a foo.
- *)
- "static method call and inheritance" >:: (fun () ->
- let file = "
- class A { static function a() { } }
- class B extends A { }
- function c() { B::a(); }
- "
- in
- let db = db_from_string file in
- (* shortcuts *)
- let id s = id s db in
- let callers id = callers id db in let _callees id = callees id db in
- (* TODO: how this works?? I have code to solve this pb? where? *)
- assert_equal
- (sort [id "c"])
- (sort (callers (id "A::a")));
- );
-
- (* PHP is very permissive regarding static method calls as one can
- * do $this->foo() even if foo is a static method. PHP does not
- * impose the X::foo() syntax, which IMHO is just wrong.
- *)
- "static method call and $this" >:: (fun () ->
- let file = "
- class A {
- static function a() { }
- function a2() { $this->a(); }
- }
- "
- in
- let db = db_from_string file in
- (* shortcuts *)
- let _id s = id s db in
- let _callers id = callers id db in let _callees id = callees id db in
- (* This currently fails, and I am not sure I want to fix it. Our
- * code should not use the $this->foo() syntax for static method
- * calls
- *
- * assert_equal
- * (sort [id "A::a2"])
- * (sort (callers (id "A::a")));
- *)
- ()
- );
-
- (* Checking method calls. *)
- "simple method call" >:: (fun () ->
- let _file = "
- class A { function foo() { } }
- function c() { $a = new A(); $a->foo(); }
- "
- in
-(* TODO
- let db = db_from_string file in
- Database_php_build2.index_db_method db;
- (* shortcuts *)
- let id s = id s db in
- let _callers id = callers id db in let callees id = callees id db in
- assert_equal
- (sort [id "A::foo"])
- (sort (callees (id "c")));
-*)
- ()
- );
-
- (* Right now the analysis is very simple and does some gross over
- * approximation. With a call like $x->foo(), the analysis consider
- * any method foo in any class as a viable candidate. Doing a better
- * job would require some class and data-flow analysis.
- * Once the analysis gets more precise, fix those tests.
- *)
- "method call approximation" >:: (fun () ->
- let _file = "
- class A { function foo() { } }
- class B { function foo() { } }
- function c() { $a = new A(); $a->foo(); }
- "
- in
-(* TODO
- let db = db_from_string file in
- Database_php_build2.index_db_method db;
- (* shortcuts *)
- let id s = id s db in
- let _callers id = callers id db in let callees id = callees id db in
- assert_equal
- (sort [id "A::foo"; id "B::foo"]) (* sad, should have only A::foo *)
- (sort (callees (id "c")));
-*)
- ()
- );
]
(*---------------------------------------------------------------------------*)
(* Classes use/def *)
(*---------------------------------------------------------------------------*)
+(* todo: port this to prolog *)
let class_unittest =
"class analysis" >::: [
@@ -396,7 +271,9 @@ let include_unittest =
]
in
let db = db_from_fake_files data in
- Database_php_build2.index_db_includes_requires None db;
+ Common.save_excursion Flag_analyze_php.verbose_database false (fun()->
+ Database_php_build2.index_db_includes_requires None db
+ );
let p file = Db.readable_to_absolute_filename file db in
@@ -16,17 +16,20 @@ open OUnit
(* todo? could perhaps be moved in its own database_prolog.ml file? *)
let prolog_query ~file query =
- let source_file = Common.new_temp_file "prolog_php" ".php" in
+ let source_file = Parse_php.tmp_php_file_from_string file in
let facts_pl_file = Common.new_temp_file "prolog_php_db" ".pl" in
let helpers_pl_file = Config.path ^ "/h_program-lang/database_code.pl" in
- Common.write_file ~file:source_file ("<?php\n" ^ file);
(* make sure it's a valid PHP file *)
let _ast = Parse_php.parse_program source_file in
+ (* todo: at some point avoid using database_php_build and
+ * gen_prolog_db directly from the sources (+ callgraph info of
+ * abstract interpreter)
+ *)
let db = Database_php_build.db_of_files_or_dirs [source_file] in
- Database_prolog_php.gen_prolog_db db facts_pl_file;
+ Database_prolog_php.gen_prolog_db ~show_progress:false db facts_pl_file;
let cmd =
- spf "swipl -s %s -f %s -t halt --quiet -g \"%s\""
+ spf "swipl -s %s -f %s -t halt --quiet -g \"%s ,fail\""
facts_pl_file helpers_pl_file query
in
let xs = Common.cmd_to_list cmd in
@@ -39,19 +42,27 @@ let prolog_query ~file query =
let unittest =
"prolog" >::: ([
+ (*-----------------------------------------------------------------------*)
+ (* Inheritance *)
+ (*-----------------------------------------------------------------------*)
+
"inheritance" >:: (fun () ->
let file = "
class A { }
class B extends A { }
class C extends B { }
"
in
- let xs = prolog_query ~file "children(X, 'A'), writeln(X), fail" in
+ let xs = prolog_query ~file "children(X, 'A'), writeln(X)" in
assert_equal ~msg:"it should find all children of a class"
(sort ["B";"C"])
(sort xs)
);
+ (*-----------------------------------------------------------------------*)
+ (* Traits *)
+ (*-----------------------------------------------------------------------*)
+
"traits" >:: (fun () ->
let file = "
trait T {
@@ -63,7 +74,7 @@ class A {
}
"
in
- let xs = prolog_query ~file "method('A', (_Class, X)), writeln(X), fail"
+ let xs = prolog_query ~file "method('A', (_Class, X)), writeln(X)"
in
assert_equal ~msg:"it should find all methods of a class using traits"
(sort ["a";"trait1"])
@@ -84,6 +95,15 @@ class A { use TComp; }
(sort xs)
);
+ (*-----------------------------------------------------------------------*)
+ (* Privacy and inheritance *)
+ (*-----------------------------------------------------------------------*)
+ (* todo: tricky when traits *)
+
+ (*-----------------------------------------------------------------------*)
+ (* Override *)
+ (*-----------------------------------------------------------------------*)
+
"overrides" >:: (fun () ->
let file = "
class A {
@@ -100,5 +120,10 @@ class B extends A { public function foo() { } }
(sort xs);
);
+
+ (*-----------------------------------------------------------------------*)
+ (* Callgraph *)
+ (*-----------------------------------------------------------------------*)
+
]
)
Oops, something went wrong.

0 comments on commit db81496

Please sign in to comment.