Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0434e17

Browse files
committed
ut_output_buffer is now fully abstracted from caller and caller can use reporter to get the output data.
Introduced new abstract type: `ut_output_reporter_base`. Every reporter based on that type is supposed to use output buffer. So for every reporter of type `ut_output_reporter_base`, client can call functions: - get_lines - lines_to_dbms_output - get_lines_cursor Also, the reporters don't need to call parent reporter's method to finalize the reporting. New finalize event is added. There is no direct dependency between `ut_runner.run` and `ut_output_buffer` so we may now pass a reporter that doesn't report to output but saves data to table for example. Removed unused code. Added unit tests for better coverage. Refactored `ut_output_buffer` package into `ut_output_table_buffer` type. Created base type for output_buffers. Created header table for table output data. Updated `ut_output_reporter_base` to contain by default `ut_output_table_buffer` Updated tests for output buffers. Refreshed list of sources for RunAll script. Addressed review comments and fixed tests stability. Removing initialization from output constructor Fixed buffer initialization. Fixed tests location after rebase.
1 parent 66b0034 commit 0434e17

61 files changed

Lines changed: 789 additions & 382 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/demo_of_expectations/demo_equal_matcher.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ create or replace package body demo_equal_matcher as
9898
l_expected demo_department;
9999
l_actual demo_department;
100100
begin
101-
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected),false);
101+
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected),a_nulls_are_equal=>false);
102102
end;
103103

104104

examples/developer_examples/RunExampleComplexSuiteWithCustomReporter.sql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ declare
1616
suite1 ut_logical_suite;
1717
suite2 ut_logical_suite;
1818
suite_complex ut_logical_suite;
19-
listener ut_event_listener;
19+
l_reporter ut_output_reporter_base;
20+
l_listener ut_event_listener;
2021
l_run ut_run;
2122
begin
2223
suite1 := ut_logical_suite(a_object_owner=>null, a_object_name => null, a_name => null, a_description => 'Test Suite 1', a_path => null);
@@ -44,10 +45,11 @@ begin
4445
suite_complex.items := ut_suite_items(suite1, suite2);
4546

4647
-- provide a reporter to process results
47-
listener := ut_event_listener(ut_reporters(ut_custom_reporter(a_tab_size => 2)));
48+
l_reporter := ut_custom_reporter(a_tab_size => 2);
49+
l_listener := ut_event_listener(ut_reporters(l_reporter));
4850
l_run := ut_run(ut_suite_items(suite_complex));
49-
l_run.do_execute(listener);
50-
ut_output_buffer.lines_to_dbms_output(listener.reporters(1).reporter_id,0);
51+
l_run.do_execute(l_listener);
52+
l_reporter.lines_to_dbms_output();
5153
end;
5254
/
5355

examples/developer_examples/RunExampleTestSuiteWithCompositeReporter.sql

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ set echo off
1212

1313
PROMPT Runs test report using composite reporter
1414
declare
15-
suite ut_logical_suite;
16-
listener ut_event_listener;
17-
l_run ut_run;
15+
suite ut_logical_suite;
16+
l_doc_reporter ut_output_reporter_base := ut_documentation_reporter();
17+
l_tc_reporter ut_output_reporter_base := ut_teamcity_reporter();
18+
l_listener ut_event_listener := ut_event_listener(ut_reporters(l_doc_reporter, l_tc_reporter));
19+
l_run ut_run;
1820
begin
1921
suite := ut_logical_suite(a_object_owner=>null, a_object_name => 'ut_exampletest', a_name => null, a_description => 'Test Suite Name',a_path => null);
2022

@@ -36,11 +38,10 @@ begin
3638
);
3739

3840
-- provide a reporter to process results
39-
listener := ut_event_listener(ut_reporters(ut_documentation_reporter, ut_teamcity_reporter));
4041
l_run := ut_run(ut_suite_items(suite));
41-
l_run.do_execute(listener);
42-
ut_output_buffer.lines_to_dbms_output(listener.reporters(1).reporter_id,0);
43-
ut_output_buffer.lines_to_dbms_output(listener.reporters(2).reporter_id,0);
42+
l_run.do_execute(l_listener);
43+
l_doc_reporter.lines_to_dbms_output(0,0);
44+
l_tc_reporter.lines_to_dbms_output(0,0);
4445
end;
4546
/
4647

examples/developer_examples/RunExampleTestSuiteWithCustomReporter.sql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ set echo off
1515

1616
declare
1717
suite ut_logical_suite;
18-
listener ut_event_listener;
18+
l_reporter ut_output_reporter_base;
19+
l_listener ut_event_listener;
1920
l_run ut_run;
2021
begin
2122
-- Install ut_custom_reporter first from example folder
@@ -40,10 +41,11 @@ begin
4041
);
4142

4243
-- provide a reporter to process results tabbing each hierarcy level by tab_size
43-
listener := ut_event_listener(ut_reporters(ut_custom_reporter(a_tab_size => 2)));
44+
l_reporter := ut_custom_reporter(a_tab_size => 2);
45+
l_listener := ut_event_listener(ut_reporters(l_reporter));
4446
l_run := ut_run(ut_suite_items(suite));
45-
l_run.do_execute(listener);
46-
ut_output_buffer.lines_to_dbms_output(listener.reporters(1).reporter_id,0);
47+
l_run.do_execute(l_listener);
48+
l_reporter.lines_to_dbms_output(0,0);
4749
end;
4850
/
4951

old_tests/RunAll.sql

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ exec ut_coverage.coverage_start_develop();
5353
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParseProcedureAnnotationWithVeryLongName.sql
5454
@@lib/RunTest.sql ut_expectation_processor/who_called_expectation.parseStackTrace.sql
5555
@@lib/RunTest.sql ut_expectation_processor/who_called_expectation.parseStackTraceWith0x.sql
56+
@@lib/RunTest.sql ut_expectations/ut.expect.not_to_equal.anydata.GivesFailureWhenComparingTheSameData.sql
5657
@@ut_expectations/ut.expect.not_to_be_null.sql
5758
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNotBoolean.sql
5859
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNull.sql
@@ -139,7 +140,8 @@ exec ut_coverage.coverage_start_develop();
139140
@@lib/RunTest.sql ut_metadata/ut_metadata.form_name.TrimStandaloneProgramName.sql
140141

141142
@@lib/RunTest.sql ut_output_buffer/get_lines.RecievesALineFromBufferTableAndDeletes.sql
142-
@@lib/RunTest.sql ut_output_buffer/send_line.DoesNotSendLineIfNullReporterIdGiven.sql
143+
@@lib/RunTest.sql ut_output_buffer/get_lines.WaitsForMoreDataToAppearForSpecifiedTime.sql
144+
@@lib/RunTest.sql ut_output_buffer/get_lines.WaitsForTheDataToAppearForSpecifiedTime.sql
143145
@@lib/RunTest.sql ut_output_buffer/send_line.DoesNotSendLineIfNullTextGiven.sql
144146
@@lib/RunTest.sql ut_output_buffer/send_line.SendsALineIntoBufferTable.sql
145147

@@ -160,6 +162,7 @@ exec ut_coverage.coverage_start_develop();
160162
@@lib/RunTest.sql ut/ut.run.AcceptsCoverageFileList.sql
161163
@@lib/RunTest.sql ut/ut.run.AcceptsCoverageFileListWithSutePaths.sql
162164
@@lib/RunTest.sql ut/ut.run.AcceptsSutePaths.sql
165+
@@lib/RunTest.sql ut/ut.run.ExecutesSuccesfullyAnEmptySuite.sql
163166
@@lib/RunTest.sql ut/ut.run.FailsToExecuteAnInvalidPackageBody.sql
164167
@@lib/RunTest.sql ut/ut.run.function.AcceptsCoverageFileList.sql
165168
@@lib/RunTest.sql ut/ut.run.function.AcceptsCoverageFileListWithSutePaths.sql
@@ -313,12 +316,12 @@ begin
313316
'source/create_synonyms_and_grants_for_public.sql',
314317
'source/create_synonyms_and_grants_for_user.sql',
315318
'source/create_utplsql_owner.sql',
319+
'source/define_ut3_owner_param.sql',
316320
'source/expectations',
317321
'source/install.log',
318322
'source/install.sql',
323+
'source/install_component.sql',
319324
'source/install_headless.sql',
320-
'source/license.txt',
321-
'source/readme.md',
322325
'source/reporters',
323326
'source/uninstall.log',
324327
'source/uninstall.sql',
@@ -340,19 +343,16 @@ begin
340343
'source/api/ut_runner.pkb',
341344
'source/api/ut_runner.pks',
342345
'source/core/coverage',
346+
'source/core/output_buffers',
343347
'source/core/types',
344348
'source/core/ut_annotations.pkb',
345349
'source/core/ut_annotations.pks',
346350
'source/core/ut_expectation_processor.pkb',
347351
'source/core/ut_expectation_processor.pks',
348352
'source/core/ut_file_mapper.pkb',
349353
'source/core/ut_file_mapper.pks',
350-
'source/core/ut_message_id_seq.sql',
351354
'source/core/ut_metadata.pkb',
352355
'source/core/ut_metadata.pks',
353-
'source/core/ut_output_buffer.pkb',
354-
'source/core/ut_output_buffer.pks',
355-
'source/core/ut_output_buffer_tmp.sql',
356356
'source/core/ut_suite_manager.pkb',
357357
'source/core/ut_suite_manager.pks',
358358
'source/core/ut_utils.pkb',
@@ -362,9 +362,15 @@ begin
362362
'source/core/coverage/ut_coverage.pks',
363363
'source/core/coverage/ut_coverage_helper.pkb',
364364
'source/core/coverage/ut_coverage_helper.pks',
365-
'source/core/coverage/ut_coverage_sources_tmp.sql',
366365
'source/core/coverage/ut_coverage_reporter_base.tpb',
367366
'source/core/coverage/ut_coverage_reporter_base.tps',
367+
'source/core/coverage/ut_coverage_sources_tmp.sql',
368+
'source/core/output_buffers/ut_message_id_seq.sql',
369+
'source/core/output_buffers/ut_output_buffer_base.tps',
370+
'source/core/output_buffers/ut_output_buffer_info_tmp.sql',
371+
'source/core/output_buffers/ut_output_buffer_tmp.sql',
372+
'source/core/output_buffers/ut_output_table_buffer.tpb',
373+
'source/core/output_buffers/ut_output_table_buffer.tps',
368374
'source/core/types/ut_console_reporter_base.tpb',
369375
'source/core/types/ut_console_reporter_base.tps',
370376
'source/core/types/ut_coverage_options.tps',
@@ -376,15 +382,18 @@ begin
376382
'source/core/types/ut_expectation_result.tpb',
377383
'source/core/types/ut_expectation_result.tps',
378384
'source/core/types/ut_expectation_results.tps',
379-
'source/core/coverage/ut_file_mapping.tps',
380-
'source/core/coverage/ut_file_mappings.tps',
385+
'source/core/types/ut_file_mapping.tpb',
386+
'source/core/types/ut_file_mapping.tps',
387+
'source/core/types/ut_file_mappings.tps',
381388
'source/core/types/ut_key_value_pair.tps',
382389
'source/core/types/ut_key_value_pairs.tps',
383390
'source/core/types/ut_logical_suite.tpb',
384391
'source/core/types/ut_logical_suite.tps',
385392
'source/core/types/ut_object_name.tpb',
386393
'source/core/types/ut_object_name.tps',
387394
'source/core/types/ut_object_names.tps',
395+
'source/core/types/ut_output_reporter_base.tpb',
396+
'source/core/types/ut_output_reporter_base.tps',
388397
'source/core/types/ut_reporters.tps',
389398
'source/core/types/ut_reporter_base.tpb',
390399
'source/core/types/ut_reporter_base.tps',
@@ -401,6 +410,7 @@ begin
401410
'source/core/types/ut_test.tpb',
402411
'source/core/types/ut_test.tps',
403412
'source/core/types/ut_varchar2_list.tps',
413+
'source/core/types/ut_varchar2_rows.tps',
404414
'source/expectations/data_values',
405415
'source/expectations/matchers',
406416
'source/expectations/ut_expectation.tpb',
@@ -431,6 +441,8 @@ begin
431441
'source/expectations/ut_expectation_varchar2.tps',
432442
'source/expectations/ut_expectation_yminterval.tpb',
433443
'source/expectations/ut_expectation_yminterval.tps',
444+
'source/expectations/data_values/ut_cursor_data.sql',
445+
'source/expectations/data_values/ut_data_value.tpb',
434446
'source/expectations/data_values/ut_data_value.tps',
435447
'source/expectations/data_values/ut_data_value_anydata.tpb',
436448
'source/expectations/data_values/ut_data_value_anydata.tps',
@@ -484,24 +496,24 @@ begin
484496
'source/expectations/matchers/ut_be_null.tps',
485497
'source/expectations/matchers/ut_be_true.tpb',
486498
'source/expectations/matchers/ut_be_true.tps',
499+
'source/expectations/matchers/ut_comparison_matcher.tpb',
500+
'source/expectations/matchers/ut_comparison_matcher.tps',
487501
'source/expectations/matchers/ut_equal.tpb',
488502
'source/expectations/matchers/ut_equal.tps',
489503
'source/expectations/matchers/ut_match.tpb',
490504
'source/expectations/matchers/ut_match.tps',
491505
'source/expectations/matchers/ut_matcher.tpb',
492506
'source/expectations/matchers/ut_matcher.tps',
493-
'source/expectations/matchers/ut_comparison_matcher.tpb',
494-
'source/expectations/matchers/ut_comparison_matcher.tps',
495507
'source/reporters/ut_ansiconsole_helper.pkb',
496508
'source/reporters/ut_ansiconsole_helper.pks',
497509
'source/reporters/ut_coverage_html_reporter.tpb',
498510
'source/reporters/ut_coverage_html_reporter.tps',
499511
'source/reporters/ut_coverage_report_html_helper.pkb',
500512
'source/reporters/ut_coverage_report_html_helper.pks',
501-
'source/reporters/ut_coveralls_reporter.tpb',
502-
'source/reporters/ut_coveralls_reporter.tps',
503513
'source/reporters/ut_coverage_sonar_reporter.tpb',
504514
'source/reporters/ut_coverage_sonar_reporter.tps',
515+
'source/reporters/ut_coveralls_reporter.tpb',
516+
'source/reporters/ut_coveralls_reporter.tps',
505517
'source/reporters/ut_documentation_reporter.tpb',
506518
'source/reporters/ut_documentation_reporter.tps',
507519
'source/reporters/ut_sonar_test_reporter.tpb',
@@ -517,31 +529,34 @@ begin
517529

518530
--run for the first time to gather coverage and timings on reporters too
519531
l_reporter := ut_coverage_html_reporter(a_project_name => 'utPLSQL v3');
520-
:html_reporter_id := l_reporter.reporter_id;
521532
l_reporter.after_calling_run(l_test_run);
533+
l_reporter.finalize();
522534

523535
l_reporter := ut_coverage_sonar_reporter();
524-
:sonar_reporter_id := l_reporter.reporter_id;
525536
l_reporter.after_calling_run(l_test_run);
537+
l_reporter.finalize();
526538

527539
l_reporter := ut_coveralls_reporter();
528-
:coveralls_reporter_id := l_reporter.reporter_id;
529540
l_reporter.after_calling_run(l_test_run);
541+
l_reporter.finalize();
530542

531543
ut_coverage.coverage_stop_develop();
532544

533545
--run for the second time to get the coverage report
534546
l_reporter := ut_coverage_html_reporter(a_project_name => 'utPLSQL v3');
535-
:html_reporter_id := l_reporter.reporter_id;
536547
l_reporter.after_calling_run(l_test_run);
548+
l_reporter.finalize();
549+
:html_reporter_id := l_reporter.get_reporter_id;
537550

538551
l_reporter := ut_coverage_sonar_reporter();
539-
:sonar_reporter_id := l_reporter.reporter_id;
540552
l_reporter.after_calling_run(l_test_run);
553+
l_reporter.finalize();
554+
:sonar_reporter_id := l_reporter.get_reporter_id;
541555

542556
l_reporter := ut_coveralls_reporter();
543-
:coveralls_reporter_id := l_reporter.reporter_id;
544557
l_reporter.after_calling_run(l_test_run);
558+
l_reporter.finalize();
559+
:coveralls_reporter_id := l_reporter.get_reporter_id;
545560
end;
546561
/
547562

@@ -551,23 +566,42 @@ set termout off
551566
set feedback off
552567
set arraysize 50
553568
spool coverage.xml
554-
exec ut_output_buffer.lines_to_dbms_output(:sonar_reporter_id);
569+
declare
570+
l_reporter ut_output_reporter_base := ut_coverage_sonar_reporter();
571+
begin
572+
l_reporter.set_reporter_id(:sonar_reporter_id);
573+
l_reporter.lines_to_dbms_output(a_initial_timeout=>1, a_timeout_sec=>1);
574+
end;
575+
/
555576
spool off
556577

557578
set termout on
558579
prompt Spooling outcomes to coverage.json
559580
set termout off
560581
spool coverage.json
561-
select * from table(ut_output_buffer.get_lines(:coveralls_reporter_id));
582+
declare
583+
l_reporter ut_output_reporter_base := ut_coveralls_reporter();
584+
begin
585+
l_reporter.set_reporter_id(:coveralls_reporter_id);
586+
l_reporter.lines_to_dbms_output(a_initial_timeout=>1, a_timeout_sec=>1);
587+
end;
588+
/
562589
spool off
563590

564591
set termout on
565592
prompt Spooling outcomes to coverage.html
566593
set termout off
567594
spool coverage.html
568-
exec ut_output_buffer.lines_to_dbms_output(:html_reporter_id);
595+
declare
596+
l_reporter ut_output_reporter_base := ut_coverage_html_reporter();
597+
begin
598+
l_reporter.set_reporter_id(:html_reporter_id);
599+
l_reporter.lines_to_dbms_output(a_initial_timeout=>1, a_timeout_sec=>1);
600+
end;
601+
/
569602
spool off
570603

604+
set termout on
571605
spool stats.log
572606
exec mystats_pkg.ms_stop(1000);
573607
spool off

old_tests/helpers/utplsql_test_reporter.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
create or replace type utplsql_test_reporter under ut_reporter_base(
1+
create or replace type utplsql_test_reporter under ut_output_reporter_base(
22
constructor function utplsql_test_reporter(self in out nocopy utplsql_test_reporter) return self as result,
33
overriding member procedure after_calling_run(self in out nocopy utplsql_test_reporter, a_run in ut_run)
44
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
set termout off
2+
create or replace package empty_suite as
3+
-- %suite
4+
5+
procedure not_a_test;
6+
end;
7+
/
8+
create or replace package body empty_suite as
9+
procedure not_a_test is begin null; end;
10+
end;
11+
/
12+
set termout on
13+
declare
14+
l_result integer;
15+
begin
16+
select *
17+
into l_result
18+
from table(ut.run('empty_suite',utplsql_test_reporter()));
19+
--Assert
20+
if l_result = ut_utils.tr_error then
21+
:test_result := ut_utils.tr_success;
22+
else
23+
dbms_output.put_line('expected failure of ''empty_suite'' got: '''||ut_utils.test_result_to_char(l_result)||'''' );
24+
end if;
25+
end;
26+
/
27+
28+
set termout off
29+
drop package empty_suite;
30+
set termout on
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--Arrange
2+
declare
3+
l_expected department$ := department$('hr');
4+
l_actual department$ := department$('hr');
5+
l_result integer;
6+
begin
7+
--Act
8+
ut.expect( anydata.convertObject(l_actual) ).not_to_equal( anydata.convertObject(l_expected) );
9+
l_result := ut_expectation_processor.get_status();
10+
--Assert
11+
if l_result = ut_utils.tr_failure then
12+
:test_result := ut_utils.tr_success;
13+
else
14+
dbms_output.put_line('expected: '''||ut_utils.tr_success||''', got: '''||l_result||'''' );
15+
end if;
16+
end;
17+
/

old_tests/ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNotBoolean.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ declare
55
begin
66
--Act
77
ut.expect( 1 ).to_( be_false() );
8+
ut.expect( 1 ).not_to( be_true() );
89
l_result := ut_expectation_processor.get_status();
910
--Assert
1011
if nvl(:test_result, ut_utils.tr_success) = ut_utils.tr_success and l_result = ut_utils.tr_failure then

old_tests/ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNull.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ declare
55
begin
66
--Act
77
ut.expect( 1 = null ).to_be_false();
8+
ut.expect( 1 = null ).not_to_be_true();
89
l_result := ut_expectation_processor.get_status();
910
--Assert
1011
if nvl(:test_result, ut_utils.tr_success) = ut_utils.tr_success and l_result = ut_utils.tr_failure then

0 commit comments

Comments
 (0)