From 62b0a65b27e16c3d56df45760fb4878cf2ede5f9 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 17 Jul 2019 11:32:07 +0200 Subject: [megaco|test] Reworked the test generator behaviour Reworked the megaco test generator (megaco_test_generator) behaviour to remove compiler warnings. --- lib/megaco/test/Makefile | 5 +++- lib/megaco/test/megaco_test_generator.erl | 36 +++++++++++++++++------- lib/megaco/test/megaco_test_megaco_generator.erl | 8 +++--- 3 files changed, 34 insertions(+), 15 deletions(-) (limited to 'lib/megaco') diff --git a/lib/megaco/test/Makefile b/lib/megaco/test/Makefile index 4ddd73eea1..b4e31765b8 100644 --- a/lib/megaco/test/Makefile +++ b/lib/megaco/test/Makefile @@ -1,7 +1,7 @@ # # %CopyrightBegin% # -# Copyright Ericsson AB 1999-2016. All Rights Reserved. +# Copyright Ericsson AB 1999-2019. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -102,6 +102,9 @@ endif ERL_COMPILE_FLAGS += $(MEGACO_ERL_COMPILE_FLAGS) +# We have a behaviour in the test catalog (megaco_test_generator) +ERL_COMPILE_FLAGS += -pa ../../megaco/test + ERL_PATH = -pa ../../megaco/examples/simple \ -pa ../../megaco/ebin \ -pa ../../et/ebin diff --git a/lib/megaco/test/megaco_test_generator.erl b/lib/megaco/test/megaco_test_generator.erl index f922afa37d..8ea7f5ddf7 100644 --- a/lib/megaco/test/megaco_test_generator.erl +++ b/lib/megaco/test/megaco_test_generator.erl @@ -47,7 +47,6 @@ print/3, print/4 ]). --export([behaviour_info/1]). %% Internal exports -export([start/4]). @@ -91,15 +90,32 @@ %%% API %%%========================================================================= -behaviour_info(callbacks) -> - [ - {init, 1}, - {handle_parse, 2}, - {handle_exec, 2}, - {terminate, 2} - ]; -behaviour_info(_Other) -> - undefined. +-callback init(Args) -> {ok, State} | {error, Reason} when + Args :: term(), + State :: term(), + Reason :: term(). + +-callback handle_parse(Instruction, State) -> + {ok, NewInstruction, NewState} | + {error, Reason} when + Instruction :: term(), + State :: term(), + NewInstruction :: term(), + NewState :: term(), + Reason :: term(). + +-callback handle_exec(Instruction, State) -> + {ok, NewState} | + {error, Reason} when + Instruction :: term(), + State :: term(), + NewState :: term(), + Reason :: term(). + +-callback terminate(Reason, State) -> + megaco:void() when + Reason :: term(), + State :: term(). %%---------------------------------------------------------------------- diff --git a/lib/megaco/test/megaco_test_megaco_generator.erl b/lib/megaco/test/megaco_test_megaco_generator.erl index 5ec4a75b73..4e0f2e334c 100644 --- a/lib/megaco/test/megaco_test_megaco_generator.erl +++ b/lib/megaco/test/megaco_test_megaco_generator.erl @@ -118,7 +118,7 @@ init([]) -> %% ----- instruction parser ----- handle_parse({debug, Debug} = Instruction, State) - when (Debug == true) orelse (Debug == false) -> + when is_boolean(Debug) -> {ok, Instruction, State}; handle_parse({expect_nothing, To} = Instruction, State) @@ -126,9 +126,9 @@ handle_parse({expect_nothing, To} = Instruction, State) {ok, Instruction, State}; handle_parse({megaco_trace, Level} = Instruction, State) - when (Level == disable) orelse - (Level == max) orelse - (Level == min) orelse + when (Level =:= disable) orelse + (Level =:= max) orelse + (Level =:= min) orelse is_integer(Level) -> {ok, Instruction, State}; -- cgit v1.2.3