Skip to content

Commit

Permalink
Added check_equal between strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsAsplund committed Sep 9, 2016
1 parent bed8907 commit ee1a623
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/check/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ combination of types
+----------------------+----------------------+
| time | time |
+----------------------+----------------------+
| string | string |
+----------------------+----------------------+

+--------------------------+-----------+-----------------+
| Preprocessor Parameter | Type | Default Value |
Expand Down
2 changes: 1 addition & 1 deletion vunit/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ def version():
"""
Returns VUnit version
"""
return '0.68.1'
return '0.69.0'
82 changes: 82 additions & 0 deletions vunit/vhdl/check/src/check.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,88 @@ package body check_pkg is
return pass;
end;

procedure check_equal(
constant got : in string;
constant expected : in string;
constant msg : in string := "";
constant level : in log_level_t := dflt;
constant line_num : in natural := 0;
constant file_name : in string := "") is
variable pass : boolean;
begin
-- pragma translate_off
check_equal(default_checker, pass, got, expected, msg, level, line_num, file_name);
-- pragma translate_on
end;

procedure check_equal(
variable pass : out boolean;
constant got : in string;
constant expected : in string;
constant msg : in string := "";
constant level : in log_level_t := dflt;
constant line_num : in natural := 0;
constant file_name : in string := "") is
begin
-- pragma translate_off
check_equal(default_checker, pass, got, expected, msg, level, line_num, file_name);
-- pragma translate_on
end;

procedure check_equal(
variable checker : inout checker_t;
variable pass : out boolean;
constant got : in string;
constant expected : in string;
constant msg : in string := "";
constant level : in log_level_t := dflt;
constant line_num : in natural := 0;
constant file_name : in string := "") is
begin
-- pragma translate_off
if got = expected then
pass := true;
check_passed(checker);
else
pass := false;
check_failed(checker,
failed_expectation_msg("Equality check", got, expected, msg),
level, line_num, file_name);
end if;
-- pragma translate_on
end;

procedure check_equal(
variable checker : inout checker_t;
constant got : in string;
constant expected : in string;
constant msg : in string := "";
constant level : in log_level_t := dflt;
constant line_num : in natural := 0;
constant file_name : in string := "") is
variable pass : boolean;
begin
-- pragma translate_off
check_equal(checker, pass, got, expected, msg, level, line_num, file_name);
-- pragma translate_on
end;

impure function check_equal(
constant got : in string;
constant expected : in string;
constant msg : in string := "";
constant level : in log_level_t := dflt;
constant line_num : in natural := 0;
constant file_name : in string := "")
return boolean is
variable pass : boolean;
begin
-- pragma translate_off
check_equal(default_checker, pass, got, expected, msg, level, line_num, file_name);
-- pragma translate_on
return pass;
end;

-----------------------------------------------------------------------------
-- check_equal
-----------------------------------------------------------------------------
Expand Down
45 changes: 45 additions & 0 deletions vunit/vhdl/check/src/check_api.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,51 @@ package check_pkg is
constant line_num : in natural := 0;
constant file_name : in string := "")
return boolean;

procedure check_equal(
constant got : in string;
constant expected : in string;
constant msg : in string := "";
constant level : in log_level_t := dflt;
constant line_num : in natural := 0;
constant file_name : in string := "");

procedure check_equal(
variable pass : out boolean;
constant got : in string;
constant expected : in string;
constant msg : in string := "";
constant level : in log_level_t := dflt;
constant line_num : in natural := 0;
constant file_name : in string := "");

procedure check_equal(
variable checker : inout checker_t;
variable pass : out boolean;
constant got : in string;
constant expected : in string;
constant msg : in string := "";
constant level : in log_level_t := dflt;
constant line_num : in natural := 0;
constant file_name : in string := "");

procedure check_equal(
variable checker : inout checker_t;
constant got : in string;
constant expected : in string;
constant msg : in string := "";
constant level : in log_level_t := dflt;
constant line_num : in natural := 0;
constant file_name : in string := "");

impure function check_equal(
constant got : in string;
constant expected : in string;
constant msg : in string := "";
constant level : in log_level_t := dflt;
constant line_num : in natural := 0;
constant file_name : in string := "")
return boolean;
-----------------------------------------------------------------------------
-- check_equal
-----------------------------------------------------------------------------
Expand Down
38 changes: 38 additions & 0 deletions vunit/vhdl/check/test/tb_check_equal.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,10 @@ begin
counting_assert(not pass, "Should return pass = false on failing check");
verify_log_call(inc_count, "Equality check failed! Got 165. Expected 90.");

-------------------------------------------------------------------------
-- Manually added test cases
-------------------------------------------------------------------------

elsif run("Test should pass on time equal time") then
get_checker_stat(stat);
check_equal(-91 ns, -91 ns);
Expand Down Expand Up @@ -614,6 +618,40 @@ begin
check_equal(check_equal_checker, pass, -91 ns, 90 ns);
counting_assert(not pass, "Should return pass = false on failing check");
verify_time_log_call(inc_count, -91 ns, 90 ns);

elsif run("Test should pass on string equal string") then
get_checker_stat(stat);
check_equal(string'("test"), string'("test"));
check_equal(pass, string'("test"), string'("test"));
counting_assert(pass, "Should return pass = true on passing check");
pass := check_equal(string'("test"), string'("test"));
counting_assert(pass, "Should return pass = true on passing check");
check_equal(string'(""), string'(""));
verify_passed_checks(stat, 4);

get_checker_stat(check_equal_checker, stat);
check_equal(check_equal_checker, string'("test"), string'("test"));
check_equal(check_equal_checker, pass, string'("test"), string'("test"));
counting_assert(pass, "Should return pass = true on passing check");
verify_passed_checks(check_equal_checker,stat, 2);

elsif run("Test should fail on string not equal string") then
check_equal(string'("test"), string'("tests"));
verify_log_call(inc_count, "Equality check failed! Got test. Expected tests.");
check_equal(string'("test"), string'("tests"), "Extra info.");
verify_log_call(inc_count, "Equality check failed! Got test. Expected tests. Extra info.");
check_equal(pass, string'("test"), string'("tests"));
counting_assert(not pass, "Should return pass = false on failing check");
verify_log_call(inc_count, "Equality check failed! Got test. Expected tests.");
pass := check_equal(string'("test"), string'("tests"));
counting_assert(not pass, "Should return pass = false on failing check");
verify_log_call(inc_count, "Equality check failed! Got test. Expected tests.");

check_equal(check_equal_checker, string'("test"), string'("tests"));
verify_log_call(inc_count, "Equality check failed! Got test. Expected tests.");
check_equal(check_equal_checker, pass, string'("test"), string'("tests"));
counting_assert(not pass, "Should return pass = false on failing check");
verify_log_call(inc_count, "Equality check failed! Got test. Expected tests.");
end if;
end loop;

Expand Down

0 comments on commit ee1a623

Please sign in to comment.