Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:24
erlang
3507-cover-Implement-support-for-maybe-.-end.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 3507-cover-Implement-support-for-maybe-.-end.patch of Package erlang
From daefc0a33e36498b5401badfc0cad6bc8a6a317e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org> Date: Tue, 9 Nov 2021 10:08:17 +0100 Subject: [PATCH 07/12] cover: Implement support for maybe ... end --- lib/tools/src/cover.erl | 12 +++++++ lib/tools/test/cover_SUITE.erl | 61 +++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/lib/tools/src/cover.erl b/lib/tools/src/cover.erl index a09f6f73de..27006199d1 100644 --- a/lib/tools/src/cover.erl +++ b/lib/tools/src/cover.erl @@ -336,6 +336,7 @@ filter_options(Options) -> {d, _Macro, _Value} -> true; export_all -> true; tuple_calls -> true; + {enable_feature,_} -> true; %FIXME: To be removed. _ -> false end end, @@ -2169,6 +2170,10 @@ munge_expr({match,Anno,ExprL,ExprR}, Vars) -> {MungedExprL, Vars2} = munge_expr(ExprL, Vars), {MungedExprR, Vars3} = munge_expr(ExprR, Vars2), {{match,Anno,MungedExprL,MungedExprR}, Vars3}; +munge_expr({maybe_match,Anno,ExprL,ExprR}, Vars) -> + {MungedExprL, Vars2} = munge_expr(ExprL, Vars), + {MungedExprR, Vars3} = munge_expr(ExprR, Vars2), + {{maybe_match,Anno,MungedExprL,MungedExprR}, Vars3}; munge_expr({tuple,Anno,Exprs}, Vars) -> {MungedExprs, Vars2} = munge_exprs(Exprs, Vars, []), {{tuple,Anno,MungedExprs}, Vars2}; @@ -2260,6 +2265,13 @@ munge_expr({'try',Anno,Body,Clauses,CatchClauses,After}, Vars) -> {MungedAfter, Vars4} = munge_body(After, Vars3), {{'try',Anno,MungedBody,MungedClauses,MungedCatchClauses,MungedAfter}, Vars4}; +munge_expr({'maybe',Anno,Exprs}, Vars) -> + {MungedExprs, Vars2} = munge_body(Exprs, Vars), + {{'maybe',Anno,MungedExprs}, Vars2}; +munge_expr({'maybe',MaybeAnno,Exprs,{'else',ElseAnno,Clauses}}, Vars) -> + {MungedExprs, Vars2} = munge_body(Exprs, Vars), + {MungedClauses, Vars3} = munge_clauses(Clauses, Vars2), + {{'maybe',MaybeAnno,MungedExprs,{'else',ElseAnno,MungedClauses}}, Vars3}; munge_expr({'fun',Anno,{clauses,Clauses}}, Vars) -> {MungedClauses,Vars2}=munge_clauses(Clauses, Vars), {{'fun',Anno,{clauses,MungedClauses}}, Vars2}; diff --git a/lib/tools/test/cover_SUITE.erl b/lib/tools/test/cover_SUITE.erl index 19550455db..9a2479bd94 100644 --- a/lib/tools/test/cover_SUITE.erl +++ b/lib/tools/test/cover_SUITE.erl @@ -32,7 +32,8 @@ all() -> otp_8340,otp_8188,compile_beam_opts,eep37, analyse_no_beam, line_0, compile_beam_no_file, compile_beam_missing_backend, - otp_13277, otp_13289, guard_in_lc, gh_4796], + otp_13277, otp_13289, guard_in_lc, gh_4796, + eep49], StartStop = [start, compile, analyse, misc, stop, distribution, reconnect, die_and_reconnect, dont_reconnect_after_stop, stop_node_after_disconnect, @@ -1895,6 +1896,64 @@ gh_4796(Config) -> ok = file:delete(File), ok = gh_4796:test(). +%% Test the maybe ... else ... end construct. +eep49(Config) -> + ok = file:set_cwd(proplists:get_value(priv_dir, Config)), + + File = "t.erl", + Test = <<"-module(t). + -export([t/0]). + -compile([{enable_feature,'maybe'}]). + + t() -> + t1(), %6 + + {a,b} = t2({ok,a}, {ok,b}), %8 + error = t2({ok,a}, error), %9 + whatever = t2(whatever, thing), %10 + + {a,b} = t3({ok,a}, {ok,b}), %12 + error = t3({ok,a}, {error,wrong}), %13 + {'EXIT',{{else_clause,whatever},_}} = catch t3(whatever, thing), %14 + + ok. %16 + + t1() -> + maybe %19 + ok %20 + end. + + t2(X, Y) -> + maybe %24 + {ok,A} ?= X, %25 + {ok,B} ?= Y, %26 + {A,B} %27 + end. + + t3(X, Y) -> + maybe %31 + {ok,A} ?= X, %32 + {ok,B} ?= Y, %33 + {A,B} %34 + else + {error,_} -> + error %37 + end. + ">>, + ok = file:write_file(File, Test), + %% FIXME: Remove `enable_feature` option here when it can be recognized inside a module. + {ok, t} = cover:compile(File, [{enable_feature,maybe_expr}]), + ok = t:t(), + {ok,[{{t,6},1}, {{t,8},1}, {{t,9},1}, {{t,10},1}, {{t,12},1}, + {{t,13},1}, {{t,14},1}, {{t,16},1}, + {{t,19},1}, {{t,20},1}, + {{t,24},3}, {{t,25},3}, {{t,26},2}, {{t,27},1}, + {{t,31},3}, {{t,32},3}, {{t,33},2}, {{t,34},1}, {{t,37},1} + ]} = cover:analyse(t, calls, line), + ok = file:delete(File), + ok. + + %%--Auxiliary------------------------------------------------------------ analyse_expr(Expr, Config) -> -- 2.34.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor