diff --git a/LICENSE.md b/LICENSE.md index e34262b5..525b7116 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2025, [CyberDojo Foundation](http://blog.cyber-dojo.org/2015/08/cyber-dojo-foundation.html) +Copyright (c) 2026, [CyberDojo Foundation](http://blog.cyber-dojo.org/2015/08/cyber-dojo-foundation.html) All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index 7dfb2d43..d50194f2 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,7 @@ $ make {image_server|image_client} # Run all tests $ make {test_server|test_client} -# Run only specific tests -$ ./bin/run_tests.sh {-h|--help} -$ ./bin/run_tests.sh {server|client} B56Sp3 +# Run only tests whose id starts with B56 $ make {test_server|test_client} tid=B56 # Check test metrics diff --git a/test/client/differ_client_test.rb b/test/client/differ_client_test.rb index 5f712532..73da0aae 100755 --- a/test/client/differ_client_test.rb +++ b/test/client/differ_client_test.rb @@ -4,19 +4,16 @@ require 'cgi' class DifferClientTest < ClientTestBase - def self.id58_prefix - '2q0' - end hostname = 'server' port = ENV['CYBER_DOJO_DIFFER_PORT'].to_i # - - - - - - - - - - - - - - - - - - - - - test 'jj8', %w[ - clients use probes with a trailing question mark in their path which is overly cute - so support both with and without ? until all clients have switched to non ? - ] do + test '2q0jj8', %w( + | clients use probes with a trailing question mark in their path which is overly cute + | so support both with and without ? until all clients have switched to non ? + ) do requester = HttpJsonHash::Requester.new(hostname, port) http = HttpJsonHash::Unpacker.new('differ', requester) assert http.get('alive?', {}).instance_of?(TrueClass) @@ -25,10 +22,10 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test 'jj9', %w( - /diff_summary can use GET query args - which is important since in jQuery a $.getJSON() call - always passes its arguments in the query string + test '2q0jj9', %w( + | /diff_summary can use GET query args + | which is important since in jQuery a $.getJSON() call + | always passes its arguments in the query string ) do requester = HttpJsonHash::Requester.new(hostname, port) http = HttpJsonHash::Unpacker.new('differ', requester) @@ -73,16 +70,18 @@ def self.id58_prefix # >10K query was a problem for thin at one time # - - - - - - - - - - - - - - - - - - - - - test '347', - '>10K query is not rejected by web server' do + test '2q0347', %w( + | >10K query is not rejected by web server + ) do @old_files = { 'wibble.h' => 'X' * 45 * 1024 } @new_files = {} id, was_index, now_index = *run_diff_prepare differ.diff_summary(id, was_index, now_index) end - test '348', - '>10K query in nested sub-dir is not rejected by web-server' do + test '2q0348', %w( + | >10K query in nested sub-dir is not rejected by web-server + ) do @old_files = { 'gh/jk/wibble.h' => 'X' * 45 * 1024 } @new_files = {} id, was_index, now_index = *run_diff_prepare @@ -91,12 +90,16 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test '944', 'probes 200' do + test '2q0944', %w( + | probes 200 + ) do assert differ.alive.instance_of?(TrueClass) assert differ.ready.instance_of?(TrueClass) end - test '945', 'sha 200' do + test '2q0945', %w( + | sha 200 + ) do sha = differ.sha assert_equal 40, sha.size, 'sha.size' sha.each_char do |ch| @@ -108,7 +111,9 @@ def self.id58_prefix # failure cases # - - - - - - - - - - - - - - - - - - - - - test '7C0', %w[calling unknown method raises] do + test '2q07C0', %w( + | calling unknown method raises + ) do requester = HttpJsonHash::Requester.new(hostname, port) http = HttpJsonHash::Unpacker.new('differ', requester) error = assert_raises(RuntimeError) { http.get(:shar, { x: 42 }) } @@ -131,8 +136,9 @@ def self.id58_prefix # delete file # - - - - - - - - - - - - - - - - - - - - - test '313', - 'deleted empty file' do + test '2q0313', %w( + | deleted empty file + ) do @old_files = { 'hiker.h' => '' } @new_files = {} assert_diff( @@ -158,8 +164,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test '314', - 'deleted empty file in nested sub-dir' do + test '2q0314', %w( + | deleted empty file in nested sub-dir + ) do @old_files = { '6/7/8/hiker.h' => '' } @new_files = {} assert_diff( @@ -175,8 +182,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test 'FE9', - 'deleted non-empty file shows as all lines deleted' do + test '2q0FE9', %w( + | deleted non-empty file shows as all lines deleted + ) do @old_files = { 'hiker.h' => "a\nb\nc\nd\n" } @new_files = {} assert_diff( @@ -208,8 +216,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test 'FEA', - 'deleted non-empty file in nested sub-dir shows as all lines deleted' do + test '2q0FEA', %w( + | deleted non-empty file in nested sub-dir shows as all lines deleted + ) do @old_files = { '4/5/6/7/hiker.h' => "a\nb\nc\nd\n" } @new_files = {} assert_diff( @@ -233,9 +242,10 @@ def self.id58_prefix # delete content # - - - - - - - - - - - - - - - - - - - - - test 'B67', - 'all lines deleted but file not deleted', - 'shows as all lines deleted' do + test '2q0B67', %w( + | all lines deleted but file not deleted + | shows as all lines deleted + ) do @old_files = { 'hiker.h' => "a\nb\nc\nd\n" } @new_files = { 'hiker.h' => '' } assert_diff( @@ -257,9 +267,10 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test 'B68', - 'all lines deleted but nested sub-dir file not deleted', - 'shows as all lines deleted' do + test '2q0B68', %w( + | all lines deleted but nested sub-dir file not deleted + | shows as all lines deleted + ) do @old_files = { 'r/t/y/hiker.h' => "a\nb\nc\nd\n" } @new_files = { 'r/t/y/hiker.h' => '' } assert_diff( @@ -283,8 +294,9 @@ def self.id58_prefix # new file # - - - - - - - - - - - - - - - - - - - - - test '95F', - %w[created new empty file] do + test '2q095F', %w( + | created new empty file + ) do @old_files = {} @new_files = { 'diamond.h' => '' } assert_diff( @@ -300,8 +312,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test '960', - %w[created empty file in nested sub-dir] do + test '2q0960', %w( + | created empty file in nested sub-dir + ) do @old_files = {} @new_files = { 'a/b/c/diamond.h' => '' } assert_diff( @@ -327,8 +340,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test '2C3', - %w[created non-empty file] do + test '2q02C3', %w( + | created non-empty file + ) do @old_files = {} @new_files = { 'diamond.h' => "a\nb\nc\nd" } assert_diff( @@ -350,8 +364,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test '2C4', - %w[created non-empty file in nested sub-dir] do + test '2q02C4', %w( + | created non-empty file in nested sub-dir + ) do @old_files = {} @new_files = { 'q/w/e/diamond.h' => "a\nb\nc\nd" } assert_diff( @@ -375,8 +390,9 @@ def self.id58_prefix # change # - - - - - - - - - - - - - - - - - - - - - test 'E3E', - %w[changed non-empty file] do + test '2q0E3E', %w( + | changed non-empty file + ) do @old_files = { 'diamond.h' => 'a' } @new_files = { 'diamond.h' => 'b' } assert_diff( @@ -396,8 +412,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test 'E3F', - %w[changed non-empty file in nested sub-dir] do + test '2q0E3F', %w( + | changed non-empty file in nested sub-dir + ) do @old_files = { 't/y/u/diamond.h' => 'a1' } @new_files = { 't/y/u/diamond.h' => 'b2' } assert_diff( @@ -417,9 +434,10 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test 'B9E', - 'changed non-empty file shows as deleted and added lines', - 'with each hunk in its own indexed section' do + test '2q0B9E', %w( + | changed non-empty file shows as deleted and added lines + | with each hunk in its own indexed section + ) do @old_files = { 'diamond.h' => [ @@ -475,9 +493,10 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test 'B9F', - 'changed non-empty file in nested sub-dir shows as deleted and added lines', - 'with each hunk in its own indexed section' do + test '2q0B9F', %w( + | changed non-empty file in nested sub-dir shows as deleted and added lines + | with each hunk in its own indexed section + ) do @old_files = { 'a/b/c/diamond.h' => [ @@ -535,8 +554,9 @@ def self.id58_prefix # renamed file # - - - - - - - - - - - - - - - - - - - - - test 'E50', - '100% identical renamed file' do + test '2q0E50', %w( + | 100% identical renamed file + ) do @old_files = { 'hiker.h' => "a\nb\nc\nd" } @new_files = { 'diamond.h' => "a\nb\nc\nd" } assert_diff( @@ -567,8 +587,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test 'E51', - '100% identical renamed file in nested sub-dir' do + test '2q0E51', %w( + | 100% identical renamed file in nested sub-dir + ) do @old_files = { 'a/f/d/hiker.h' => "a\nb\nc\nd" } @new_files = { 'a/f/d/diamond.h' => "a\nb\nc\nd" } assert_diff( @@ -589,8 +610,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test 'FDB', - '<100% identical rename' do + test '2q0FDB', %w( + | <100% identical rename + ) do @old_files = { 'hiker.h' => "a\nb\nc\nd" } @new_files = { 'diamond.h' => "a\nb\nX\nd" } assert_diff( @@ -613,8 +635,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test 'FDC', - '<100% identical renamed in nested sub-dir' do + test '2q0FDC', %w( + | <100% identical renamed in nested sub-dir + ) do @old_files = { 'a/b/c/hiker.h' => "a\nb\nc\nd" } @new_files = { 'a/b/c/diamond.h' => "a\nb\nX\nd" } assert_diff( @@ -639,8 +662,9 @@ def self.id58_prefix # unchanged files # - - - - - - - - - - - - - - - - - - - - - test 'AEC', - 'unchanged empty files' do + test '2q0AEC', %w( + | unchanged empty files + ) do @old_files = { 'diamond.h' => '' } @new_files = { 'diamond.h' => '' } assert_diff( @@ -656,8 +680,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test '7FF', - 'unchanged empty-file in nested sub-dir' do + test '2q07FF', %w( + | unchanged empty-file in nested sub-dir + ) do @old_files = { 'w/e/r/diamond.h' => '' } @new_files = { 'w/e/r/diamond.h' => '' } assert_diff( @@ -673,8 +698,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test '365', - 'unchanged non-empty file' do + test '2q0365', %w( + | unchanged non-empty file + ) do @old_files = { 'diamond.h' => "a\nb\nc\nd" } @new_files = { 'diamond.h' => "a\nb\nc\nd" } assert_diff( @@ -695,8 +721,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - test '366', - 'unchanged non-empty file in nested sub-dir shows as all lines same' do + test '2q0366', %w( + | unchanged non-empty file in nested sub-dir shows as all lines same + ) do @old_files = { 'r/t/y/diamond.h' => "a\nbb\nc\nd" } @new_files = { 'r/t/y/diamond.h' => "a\nbb\nc\nd" } assert_diff( @@ -825,4 +852,5 @@ def line(text, type, number) def section(index) { 'type' => 'section', 'index' => index } end + end diff --git a/test/client/http_response_unpacker_test.rb b/test/client/http_response_unpacker_test.rb index 4344c174..61aee832 100644 --- a/test/client/http_response_unpacker_test.rb +++ b/test/client/http_response_unpacker_test.rb @@ -5,11 +5,6 @@ require 'ostruct' class HttpResponseUnpackerTest < ClientTestBase - def self.id58_prefix - 'C20' - end - - # - - - - - - - - - - - - - - - - - class HttpJsonRequestBodyStubber def initialize(body) @@ -21,11 +16,11 @@ def get(_path, _args, _params = {}) end end - test 'QN3', %w( - |when an http-proxy - |receives a JSON-Hash in its response.body - |which has a key matching the query-string (without the args) - |then it returns the value for that key in the JSON-Hash + test 'C20QN3', %w( + | when an http-proxy + | receives a JSON-Hash in its response.body + | which has a key matching the query-string (without the args) + | then it returns the value for that key in the JSON-Hash ) do unpacker = stub('{"diff_summary":42}') diff_summary = unpacker.get('diff_summary', {}) @@ -34,42 +29,42 @@ def get(_path, _args, _params = {}) # - - - - - - - - - - - - - - - - - - test 'QN4', %w[ - |when an http-proxy - |receives non-JSON in its response.body - |it raises an exception - ] do + test 'C20QN4', %w( + | when an http-proxy + | receives non-JSON in its response.body + | it raises an exception + ) do raises_exception('xxxx', 'body is not JSON') end # - - - - - - - - - - - - - - - - - - test 'QN5', %w( - |when an http-proxy - |receives JSON (but not a Hash) in its response.body - |it raises an exception + test 'C20QN5', %w( + | when an http-proxy + | receives JSON (but not a Hash) in its response.body + | it raises an exception ) do raises_exception('[]', 'body is not JSON Hash') end # - - - - - - - - - - - - - - - - - - test 'QN6', %w[ - |when an http-proxy - |receives JSON-Hash with an exception key in its response.body - |it raises an exeption - ] do + test 'C20QN6', %w( + | when an http-proxy + | receives JSON-Hash with an exception key in its response.body + | it raises an exeption + ) do raises_exception('{"exception":42}', 'body has embedded exception') end # - - - - - - - - - - - - - - - - - - test 'QN7', %w[ - |when an http-proxy - |receives JSON-Hash in its response.body - |which does not contain the requested method's key - |it raises an exeption - ] do + test 'C20QN7', %w( + | when an http-proxy + | receives JSON-Hash in its response.body + | which does not contain the requested method's key + | it raises an exeption + ) do raises_exception('{"wibble":42}', 'body is missing diff_summary key') end @@ -88,4 +83,5 @@ def raises_exception(body_stub, expected_message) json = JSON.parse(error.message) assert_equal expected_message, json['message'] end + end diff --git a/test/client/lib/coverage_metrics_limits.rb b/test/client/lib/coverage_metrics_limits.rb index e095cd3a..213464d3 100644 --- a/test/client/lib/coverage_metrics_limits.rb +++ b/test/client/lib/coverage_metrics_limits.rb @@ -3,7 +3,7 @@ def metrics [ [ nil ], - [ 'test.lines.total' , '<=', 234 ], + [ 'test.lines.total' , '<=', 230 ], [ 'test.lines.missed' , '<=', 0 ], [ 'test.branches.total' , '<=', 0 ], [ 'test.branches.missed', '<=', 0 ], diff --git a/test/client/lib/id58_test_base.rb b/test/client/lib/id58_test_base.rb index 49335e9e..eda9cce5 100644 --- a/test/client/lib/id58_test_base.rb +++ b/test/client/lib/id58_test_base.rb @@ -27,11 +27,11 @@ def initialize(arg) @@seen_ids = [] @@timings = {} - def self.test(id58_suffix, *lines, &test_block) + def self.test(id58, *lines, &test_block) src = test_block.source_location src_file = File.basename(src[0]) src_line = src[1].to_s - id58 = checked_id58(id58_suffix, lines) + id58 = checked_id58(id58, lines) return unless @@args == [] || @@args.any? { |arg| id58.include?(arg) } name58 = lines.join(' ') @@ -50,7 +50,7 @@ def self.test(id58_suffix, *lines, &test_block) id58_teardown end } - name = "id58 '#{id58_suffix}',\n'#{name58}'" + name = "id58 '#{id58}',\n'#{name58}'" define_method("test_\n#{name}".to_sym, &execute_around) end @@ -78,25 +78,15 @@ def self.id58?(arg) arg.chars.all? { |chr| ID58_ALPHABET.include?(chr) } end - def self.checked_id58(id58_suffix, lines) - method = 'def self.id58_prefix' - pointer = "#{' ' * method.index('.')}!" - pointee = ['', pointer, method, '', ''].join("\n") - pointer = "\n\n#{pointer}" - raise "#{pointer}missing#{pointee}" unless respond_to?(:id58_prefix) - raise "#{pointer}empty#{pointee}" if id58_prefix == '' - raise "#{pointer}not id58#{pointee}" unless id58?(id58_prefix) - - method = "test '#{id58_suffix}'," + def self.checked_id58(id58, lines) + method = "test '#{id58}'," pointer = "#{' ' * method.index("'")}!" proposition = lines.join(' ') pointee = ['', pointer, method, "'#{proposition}'", '', ''].join("\n") - id58 = id58_prefix + id58_suffix pointer = "\n\n#{pointer}" - raise "#{pointer}empty#{pointee}" if id58_suffix == '' - raise "#{pointer}not id58#{pointee}" unless id58?(id58_suffix) + raise "#{pointer}empty#{pointee}" if id58 == '' + raise "#{pointer}not id58#{pointee}" unless id58?(id58) raise "#{pointer}duplicate#{pointee}" if @@seen_ids.include?(id58) - raise "#{pointer}overlap#{pointee}" if id58_prefix[-2..] == id58_suffix[0..1] @@seen_ids << id58 id58 diff --git a/test/server/diff_summary_test.rb b/test/server/diff_summary_test.rb index 3c2c9414..29880c57 100644 --- a/test/server/diff_summary_test.rb +++ b/test/server/diff_summary_test.rb @@ -3,14 +3,10 @@ require_relative 'differ_test_base' class DiffSummaryTest < DifferTestBase - def self.id58_prefix - '4DE' - end - - # - - - - - - - - - - - - - - - - - - - - - - - - - test 'j12', - 'created empty file' do + test '4DEj12', %w( + | created empty file + ) do assert_diff_summary('RNCzUr', 2, 3, :created, nil, 'empty.file', 0, 0, 0, :unchanged, 'test_hiker.sh', 'test_hiker.sh', 0, 0, 8, @@ -22,8 +18,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - test 'j13', - 'deleted empty file' do + test '4DEj13', %w( + | deleted empty file + ) do assert_diff_summary('RNCzUr', 3, 4, :deleted, 'empty.file', nil, 0, 0, 0, :unchanged, 'test_hiker.sh', 'test_hiker.sh', 0, 0, 8, @@ -35,8 +32,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - test 'j14', - 'renamed empty file' do + test '4DEj14', %w( + | renamed empty file + ) do assert_diff_summary('RNCzUr', 5, 6, :renamed, 'empty.file', 'empty.file.rename', 0, 0, 0, :unchanged, 'test_hiker.sh', 'test_hiker.sh', 0, 0, 8, @@ -48,8 +46,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - test 'j15', - 'empty file renamed 100% identical across dirs' do + test '4DEj15', %w( + | empty file renamed 100% identical across dirs + ) do assert_diff_summary('RNCzUr', 6, 7, :renamed, 'empty.file.rename', 'sub_dir/empty.file.rename', 0, 0, 0, :unchanged, 'test_hiker.sh', 'test_hiker.sh', 0, 0, 8, @@ -61,8 +60,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - test 'j16', - 'empty file has one lines added' do + test '4DEj16', %w( + | empty file has one lines added + ) do assert_diff_summary('RNCzUr', 7, 8, :changed, 'sub_dir/empty.file.rename', 'sub_dir/empty.file.rename', 1, 0, 0, :unchanged, 'test_hiker.sh', 'test_hiker.sh', 0, 0, 8, @@ -74,8 +74,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - test 'k15', - 'non-empty file deleted' do + test '4DEk15', %w( + | non-empty file deleted + ) do assert_diff_summary('RNCzUr', 8, 9, :deleted, 'readme.txt', nil, 0, 14, 0, :unchanged, 'test_hiker.sh', 'test_hiker.sh', 0, 0, 8, @@ -87,8 +88,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - test 'k16', - 'non-empty file renamed 100% identical' do + test '4DEk16', %w( + | non-empty file renamed 100% identical + ) do assert_diff_summary('RNCzUr', 9, 10, :renamed, 'bats_help.txt', 'bats_help.txt.rename', 0, 0, 3, :unchanged, 'test_hiker.sh', 'test_hiker.sh', 0, 0, 8, @@ -99,8 +101,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - test 'k17', - 'non-empty file renamed <100% identical' do + test '4DEk17', %w( + | non-empty file renamed <100% identical + ) do assert_diff_summary('RNCzUr', 13, 14, :changed, 'bats_help.txt', 'bats_help.txt', 1, 1, 19, # data error. No rename here. :unchanged, 'test_hiker.sh', 'test_hiker.sh', 0, 0, 8, @@ -111,8 +114,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - test 'k18', - 'two non-empty files both edited' do + test '4DEk18', %w( + | two non-empty files both edited + ) do assert_diff_summary('RNCzUr', 1, 2, :changed, 'hiker.sh', 'hiker.sh', 1, 1, 5, :changed, 'readme.txt', 'readme.txt', 6, 3, 8, @@ -137,4 +141,5 @@ def assert_diff_summary(id, was_index, now_index, *diffs) def diff_summary(id, was_index, now_index) differ.diff_summary(id: id, was_index: was_index, now_index: now_index) end + end diff --git a/test/server/differ_test.rb b/test/server/differ_test.rb index cb5228a4..186cfd69 100644 --- a/test/server/differ_test.rb +++ b/test/server/differ_test.rb @@ -3,9 +3,6 @@ require_relative 'differ_test_base' class DifferTest < DifferTestBase - def self.id58_prefix - 'C9s' - end def self.versions_test(id58_suffix, *lines, &block) versions = 0..2 @@ -26,7 +23,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # empty file # - - - - - - - - - - - - - - - - - - - - - - - - - versions_test 'A2C', 'empty file is created' do + versions_test 'C9sA2C', %w( + | empty file is created + ) do # Saver v2 uses git and its implementation currently relies on there # always being at least one file (cyber-dojo.sh cannot be deleted ) @was_files = { 'xx' => 'Hello' } @@ -40,7 +39,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - versions_test 'A5C', 'empty file is deleted' do + versions_test 'C9sA5C', %w( + | empty file is deleted + ) do @was_files = { 'empty.rb' => '' } @now_files = {} assert_diff [ @@ -51,7 +52,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - versions_test '3ED', 'empty file is unchanged' do + versions_test 'C9s3ED', %w( + | empty file is unchanged + ) do @was_files = { 'empty.py' => '' } @now_files = { 'empty.py' => '' } assert_diff [ @@ -62,7 +65,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - versions_test 'AA6', 'empty file is renamed 100% identical' do + versions_test 'C9sAA6', %w( + | empty file is renamed 100% identical + ) do @was_files = { 'plain' => '' } @now_files = { 'copy' => '' } assert_diff [ @@ -73,7 +78,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - versions_test 'A2D', 'empty file is renamed 100% identical across dirs' do + versions_test 'C9sA2D', %w( + | empty file is renamed 100% identical across dirs + ) do @was_files = { 'plain' => '' } @now_files = { 'a/b/copy' => '' } assert_diff [ @@ -84,7 +91,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - versions_test 'F2E', 'empty file has some content added' do + versions_test 'C9sF2E', %w( + | empty file has some content added + ) do @was_files = { 'empty.c' => '' } @now_files = { 'empty.c' => "three\nlines\nadded" } assert_diff [ @@ -102,7 +111,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # non-empty file # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - versions_test 'D09', 'non-empty file is created' do + versions_test 'C9sD09', %w( + | non-empty file is created + ) do # Saver v2 uses git and its implementation currently relies on there # always being at least one file (cyber-dojo.sh cannot be deleted ) @was_files = { 'xx' => 'Hello' } @@ -118,7 +129,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - versions_test '0C6', 'non-empty file is deleted' do + versions_test 'C9s0C6', %w( + | non-empty file is deleted + ) do @was_files = { 'non-empty.h' => "two\nlines" } @now_files = {} assert_diff [ @@ -133,7 +146,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - versions_test '21D', 'non-empty file is unchanged' do + versions_test 'C9s21D', %w( + | non-empty file is unchanged + ) do @was_files = { 'non-empty.h' => '#include' } @now_files = { 'non-empty.h' => '#include' } assert_diff [ @@ -146,7 +161,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - versions_test 'AA7', 'non-empty file is renamed 100% identical' do + versions_test 'C9sAA7', %w( + | non-empty file is renamed 100% identical + ) do @was_files = { 'plain' => 'xxx' } @now_files = { 'copy' => 'xxx' } assert_diff [ @@ -159,7 +176,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - versions_test 'BA7', 'non-empty file is renamed 100% identical across dirs' do + versions_test 'C9sBA7', %w( + | non-empty file is renamed 100% identical across dirs + ) do @was_files = { 'a/b/plain' => "a\nb\nc\nd" } @now_files = { 'copy' => "a\nb\nc\nd" } assert_diff [ @@ -175,7 +194,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - versions_test 'AA8', 'non-empty file is renamed <100% identical' do + versions_test 'C9sAA8', %w( + | non-empty file is renamed <100% identical + ) do @was_files = { 'hiker.h' => "a\nb\nc\nd" } @now_files = { 'diamond.h' => "a\nb\nX\nd" } assert_diff [ @@ -193,7 +214,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - versions_test 'AA9', 'non-empty file is renamed <100% identical across dirs' do + versions_test 'C9sAA9', %w( + | non-empty file is renamed <100% identical across dirs + ) do @was_files = { '1/2/hiker.h' => "a\nb\nc\nd" } @now_files = { '3/4/diamond.h' => "a\nb\nX\nd" } assert_diff [ @@ -211,7 +234,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - versions_test '4D0', 'non-empty file has some content added at the start' do + versions_test 'C9s4D0', %w( + | non-empty file has some content added at the start + ) do @was_files = { 'non-empty.c' => 'something' } @now_files = { 'non-empty.c' => "more\nsomething" } assert_diff [ @@ -226,7 +251,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - versions_test '4D1', 'non-empty file has some content added at the end' do + versions_test 'C9s4D1', %w( + | non-empty file has some content added at the end + ) do @was_files = { 'non-empty.c' => 'something' } @now_files = { 'non-empty.c' => "something\nmore" } assert_diff [ @@ -241,7 +268,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - versions_test '4D2', 'non-empty file has some content added in the middle' do + versions_test 'C9s4D2', %w( + | non-empty file has some content added in the middle + ) do @was_files = { 'non-empty.c' => "a\nc" } @now_files = { 'non-empty.c' => "a\nB\nc" } assert_diff [ @@ -257,7 +286,9 @@ def self.version_test(version, id58_suffix, *lines, &block) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - version_test 2, '4D3', 'diff-lines with a non-existent now-index raises reasonable exception' do + version_test 2, 'C9s4D3', %w( + | diff-lines with a non-existent now-index raises reasonable exception + ) do manifest = starter_manifest manifest['version'] = 2 id = saver.kata_create(manifest) @@ -392,4 +423,5 @@ def added(number, line) def one_line(type, number, line) { type: type, number: number, line: line } end + end diff --git a/test/server/external_disk_writer_test.rb b/test/server/external_disk_writer_test.rb index a07a8364..20b39e4b 100755 --- a/test/server/external_disk_writer_test.rb +++ b/test/server/external_disk_writer_test.rb @@ -3,12 +3,10 @@ require_relative 'differ_test_base' class ExternalDiskWriterTest < DifferTestBase - def self.id58_prefix - 'FDF' - end - test 'D4C', - 'what gets written gets read back' do + test 'FDFD4C', %w( + | what gets written gets read back + ) do Dir.mktmpdir('file_writer') do |tmp_dir| pathed_filename = "#{tmp_dir}/limerick.txt" content = 'the boy stood on the burning deck' @@ -16,4 +14,5 @@ def self.id58_prefix File.open(pathed_filename, 'r') { |fd| assert_equal content, fd.read } end end + end diff --git a/test/server/external_gitter_test.rb b/test/server/external_gitter_test.rb index eb71d7de..74804dbd 100755 --- a/test/server/external_gitter_test.rb +++ b/test/server/external_gitter_test.rb @@ -4,9 +4,6 @@ require_relative 'spy_sheller' class ExternalGitterTest < DifferTestBase - def self.id58_prefix - 'DC3' - end def id58_setup externals.instance_eval { @shell = SpySheller.new } @@ -14,8 +11,9 @@ def id58_setup # - - - - - - - - - - - - - - - - - - test '0B4', - 'git.setup' do + test 'DC30B4', %w( + | git.setup + ) do expected = [ 'git init --quiet', "git config user.name 'differ'", @@ -27,8 +25,9 @@ def id58_setup # - - - - - - - - - - - - - - - - - - test '8AB', - 'for git.add_commit_tag_0' do + test 'DC38AB', %w( + | for git.add_commit_tag_0 + ) do expected = [ 'git add .', 'git commit --allow-empty --all --message 0 --quiet', @@ -38,8 +37,9 @@ def id58_setup assert_shell(expected) end - test '8AC', - 'for git.add_commit_tag_1' do + test 'DC38AC', %w( + | for git.add_commit_tag_1 + ) do expected = [ 'git add .', 'git commit --allow-empty --all --message 1 --quiet', @@ -51,8 +51,9 @@ def id58_setup # - - - - - - - - - - - - - - - - - - test '9A2', - 'git.diff_0_1' do + test 'DC39A2', %w( + | git.diff_0_1 + ) do expected = [ 'git diff', '--unified=99999999999', @@ -77,4 +78,5 @@ def assert_shell(*messages) def path 'a/b/c/' end + end diff --git a/test/server/external_sheller_test.rb b/test/server/external_sheller_test.rb index 66d53dc3..50746071 100755 --- a/test/server/external_sheller_test.rb +++ b/test/server/external_sheller_test.rb @@ -3,26 +3,24 @@ require_relative 'differ_test_base' class ExternalShellerTest < DifferTestBase - def self.id58_prefix - 'C89' - end - - # - - - - - - - - - - - - - - - - - - test 'DBB', - 'assert_exec(*commands) returns stdout when the commands all succeed' do + test 'C89DBB', %w( + | assert_exec(*commands) returns stdout when the commands all succeed + ) do assert_equal 'Hello', shell.assert_exec('echo -n Hello') end - test '0B8', - 'assert_cd_exec(path,*commands) returns stdout when the cd and the commands succeeds' do + test 'C890B8', %w( + | assert_cd_exec(path,*commands) returns stdout when the cd and the commands succeeds + ) do assert_equal 'Hello', shell.assert_cd_exec('.', 'echo -n Hello') end # - - - - - - - - - - - - - - - - - - test 'AF6', - 'assert_exec(*commands) raises when a command fails' do + test 'C89AF6', %w( + | assert_exec(*commands) raises when a command fails + ) do error = assert_raises { shell.assert_exec('zzzz') } json = JSON.parse(error.message) assert_equal '', json['stdout'] @@ -30,8 +28,9 @@ def self.id58_prefix assert_equal 127, json['exit_status'] end - test 'ACD', - 'assert_cd_exec(path,*commands) raises when the cd fails' do + test 'C89ACD', %w( + | assert_cd_exec(path,*commands) raises when the cd fails + ) do error = assert_raises { shell.assert_cd_exec('zzzz', 'echo -n Hello') } json = JSON.parse(error.message) assert_equal '', json['stdout'] @@ -40,12 +39,14 @@ def self.id58_prefix assert_equal 2, json['exit_status'] end - test '995', - 'assert_cd_exec(path,*commands) raises when a command fails' do + test 'C89995', %w( + | assert_cd_exec(path,*commands) raises when a command fails + ) do error = assert_raises { shell.assert_cd_exec('.', 'zzzz') } json = JSON.parse(error.message) assert_equal '', json['stdout'] assert json['stderr'].end_with?("sh: zzzz: not found\n"), json['stderr'] assert_equal 127, json['exit_status'] end + end diff --git a/test/server/externals_test.rb b/test/server/externals_test.rb index 1674ad05..b284713b 100755 --- a/test/server/externals_test.rb +++ b/test/server/externals_test.rb @@ -3,26 +3,27 @@ require_relative 'differ_test_base' class ExternalsTest < DifferTestBase - def self.id58_prefix - '7A9' - end - test '920', - 'default disk is ExternalDiskWriter' do + test '7A9920', %w( + | default disk is ExternalDiskWriter + ) do assert_equal External::DiskWriter, disk.class end # - - - - - - - - - - - - - - - - - - test 'C8F', - 'default git is ExternalGitter' do + test '7A9C8F', %w( + | default git is ExternalGitter + ) do assert_equal External::Gitter, git.class end # - - - - - - - - - - - - - - - - - - test '1B1', - 'default shell is ExternalSheller' do + test '7A91B1', %w( + | default shell is ExternalSheller + ) do assert_equal External::Sheller, shell.class end + end diff --git a/test/server/git_diff_parse_filenames_test.rb b/test/server/git_diff_parse_filenames_test.rb index 5fb933c6..e8a8fb4d 100644 --- a/test/server/git_diff_parse_filenames_test.rb +++ b/test/server/git_diff_parse_filenames_test.rb @@ -4,16 +4,14 @@ require_app 'git_diff_parse_filenames' class GitDiffParseFilenamesTest < DifferTestBase - def self.id58_prefix - 'wK7' - end # - - - - - - - - - - - - - - - - - - - - - - - - - - - # parse_old_new_filenames() # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test 'D5F', - 'parse old & new filenames with space in both filenames' do + test 'wK7D5F', %w( + | parse old & new filenames with space in both filenames + ) do header = [ 'diff --git "e mpty.h" "e mpty.h"', 'index 0000000..e69de29' @@ -25,8 +23,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test '1B5', - 'parse old & new filenames with double-quote and space in both filenames' do + test 'wK71B5', %w( + | parse old & new filenames with double-quote and space in both filenames + ) do # double-quote " is a legal character in a linux filename header = [ 'diff --git "li n\"ux" "em bed\"ded"', @@ -39,8 +38,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test '50A', - 'parse old & new filenames with double-quote and space only in new-filename' do + test 'wK750A', %w( + | parse old & new filenames with double-quote and space only in new-filename + ) do # git diff only double quotes filenames if it has to header = [ 'diff --git plain "em bed\"ded"', @@ -53,8 +53,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test '4D8', - 'parse old & new filenames with double-quote and space only in old-filename' do + test 'wK74D8', %w( + | parse old & new filenames with double-quote and space only in old-filename + ) do # double-quote " is a legal character in a linux filename header = [ 'diff --git "emb ed\"ded" plain', @@ -67,8 +68,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test '740', - 'new_filename is nil for for deleted file' do + test 'wK7740', %w( + | new_filename is nil for for deleted file + ) do header = [ 'diff --git Deleted.java Deleted.java', 'deleted file mode 100644', @@ -81,8 +83,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test '2A9', - 'old_filename is nil for new file' do + test 'wK72A9', %w( + | old_filename is nil for new file + ) do header = [ 'diff --git empty.h empty.h', 'new file mode 100644', @@ -95,8 +98,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test 'A90', - 'parse old & new filenames for renamed file' do + test 'wK7A90', %w( + | parse old & new filenames for renamed file + ) do diff_lines = [ 'diff --git old_name.h "new \"name.h"', 'similarity index 100%', @@ -110,8 +114,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test 'AD7', - 'parse old & new filenames for new file in nested sub-dir' do + test 'wK7AD7', %w( + | parse old & new filenames for new file in nested sub-dir + ) do header = [ 'diff --git 1/2/3/empty.h 1/2/3/empty.h', 'new file mode 100644', @@ -124,8 +129,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test 'AD8', - 'parse old & new filenames for renamed file in nested sub-dir' do + test 'wK7AD8', %w( + | parse old & new filenames for renamed file in nested sub-dir + ) do diff_lines = [ 'diff --git 1/2/3/old_name.h 1/2/3/new_name.h', 'similarity index 100%', @@ -139,8 +145,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test 'AD9', - 'parse old & new filenames for renamed file across nested sub-dir' do + test 'wK7AD9', %w( + | parse old & new filenames for renamed file across nested sub-dir + ) do diff_lines = [ 'diff --git 1/2/3/old_name.h 4/5/6/new_name.h', 'similarity index 100%', @@ -154,10 +161,10 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test 'AD0', %w[ - parse old & new nested sub-dir filenames - with double-quote and space in both filenames - ] do + test 'wK7AD0', %w( + | parse old & new nested sub-dir filenames + | with double-quote and space in both filenames + ) do # double-quote " is a legal character in a linux filename header = [ 'diff --git "s/d/f/li n\"ux" "u/i/o/em bed\"ded"', @@ -170,12 +177,12 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test 'AD1', %w[ - parse old & new nested sub-dir filenames - with double-quote and space in both filenames - and where first sub-dir is a or b which could clash - with git-diff output which uses a/ and b/ - ] do + test 'wK7AD1', %w( + | parse old & new nested sub-dir filenames + | with double-quote and space in both filenames + | and where first sub-dir is a or b which could clash + | with git-diff output which uses a/ and b/ + ) do # double-quote " is a legal character in a linux filename header = [ 'diff --git "a/d/f/li n\"ux" "b/u/i/o/em bed\"ded"', diff --git a/test/server/git_diff_parser_test.rb b/test/server/git_diff_parser_test.rb index 109349ff..a52af258 100755 --- a/test/server/git_diff_parser_test.rb +++ b/test/server/git_diff_parser_test.rb @@ -3,14 +3,10 @@ require_relative 'differ_test_base' class GitDiffParserTest < DifferTestBase - def self.id58_prefix - 'B56' - end - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test 'sP3', - 'empty options in ctor gives no lines and no line_counts' do + test 'B56sP3', %w( + | empty options in ctor gives no lines and no line_counts + ) do diff = [ 'diff --git instructions instructions_new', 'similarity index 87%', @@ -50,8 +46,9 @@ def self.id58_prefix # parse_all # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test 'E10', - 'parse diff containing filename with backslash' do + test 'B56E10', %w( + | parse diff containing filename with backslash + ) do diff = [ 'diff --git "\\\\was_newfile_FIU" "\\\\was_newfile_FIU"', 'deleted file mode 100644', @@ -82,8 +79,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test '196', - 'parse diff deleted file' do + test 'B56196', %w( + | parse diff deleted file + ) do diff = [ 'diff --git original original', 'deleted file mode 100644', @@ -106,8 +104,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test '0FE', - 'parse another diff-form of a deleted file' do + test 'B560FE', %w( + | parse another diff-form of a deleted file + ) do diff = [ 'diff --git untitled.rb untitled.rb', 'deleted file mode 100644', @@ -141,8 +140,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test 'D91', - 'parse diff for renamed but unchanged file and newname is quoted' do + test 'B56D91', %w( + | parse diff for renamed but unchanged file and newname is quoted + ) do diff = [ 'diff --git "was_\\\\wa s_newfile_FIU" "\\\\was_newfile_FIU"', 'similarity index 100%', @@ -166,8 +166,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test 'E38', - 'parse diff for renamed but unchanged file' do + test 'B56E38', %w( + | parse diff for renamed but unchanged file + ) do diff = [ 'diff --git oldname newname', 'similarity index 100%', @@ -191,8 +192,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test 'A61', - 'parse diff for renamed and changed file' do + test 'B56A61', %w( + | parse diff for renamed and changed file + ) do diff = [ 'diff --git instructions instructions_new', 'similarity index 87%', @@ -244,8 +246,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test '91D', - 'parse diffs for two files' do + test 'B5691D', %w( + | parse diffs for two files + ) do diff = [ 'diff --git lines lines', 'index 1d60b70..14fc1c2 100644', @@ -302,8 +305,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test '1BC', - 'two hunks with no newline at end of file' do + test 'B561BC', %w( + | two hunks with no newline at end of file + ) do diff = [ 'diff --git lines lines', 'index f70c2c0..ba0f878 100644', @@ -342,8 +346,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test 'B2C', - 'diff one-hunk one-line' do + test 'B56B2C', %w( + | diff one-hunk one-line + ) do diff = [ 'diff --git lines lines', 'index 72943a1..f761ec1 100644', @@ -372,8 +377,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test 'A8A', - 'standard diff' do + test 'B56A8A', %w( + | standard diff + ) do diff = [ 'diff --git gapper.rb gapper.rb', 'index 26bc41b..8a5b0b7 100644', @@ -404,8 +410,9 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test '3B5', - 'find copies harder finds a rename' do + test 'B563B5', %w( + | find copies harder finds a rename + ) do diff = [ 'diff --git hiker.h diamond.h', 'similarity index 99%', @@ -420,11 +427,11 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - - - - - - - - - - - test '124', %w[ - renamed but unchanged file has no trailing - --- or +++ lines and must not consume diff - of following file as its header_lines - ] do + test 'B56124', %w( + | renamed but unchanged file has no trailing + | --- or +++ lines and must not consume diff + | of following file as its header_lines + ) do diff = [ 'diff --git hiker.h hiker.txt', 'similarity index 100%', @@ -475,4 +482,5 @@ def added(number, line) def src(type, number, line) { type: type, number: number, line: line } end + end diff --git a/test/server/http_proxy_response_test.rb b/test/server/http_proxy_response_test.rb index 242488ce..c76af862 100644 --- a/test/server/http_proxy_response_test.rb +++ b/test/server/http_proxy_response_test.rb @@ -4,17 +4,12 @@ require_relative 'http_adapter_stub' class HttpProxyResponseTest < DifferTestBase - def self.id58_prefix - 'f28' - end - - # - - - - - - - - - - - - - - - - - - test 'QN3', %w( - |when an http-proxy - |receives a JSON-Hash in its response.body - |which has a key matching the query-string (without the args) - |then it returns the value for that key in the JSON-Hash + test 'f28QN3', %w( + | when an http-proxy + | receives a JSON-Hash in its response.body + | which has a key matching the query-string (without the args) + | then it returns the value for that key in the JSON-Hash ) do externals.instance_exec { @saver_http = ::HttpAdapterStub.new('{"ready?":[42]}') } saver = ::External::Saver.new(externals) @@ -23,21 +18,21 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - test 'QN4', %w[ - |when an http-proxy - |receives non-JSON in its response.body - |it raises an exception - ] do + test 'f28QN4', %w( + | when an http-proxy + | receives non-JSON in its response.body + | it raises an exception + ) do stub_saver_http('xxxx') ready_raises_exception('body is not JSON') end # - - - - - - - - - - - - - - - - - - test 'QN5', %w( - |when an http-proxy - |receives JSON (but not a Hash) in its response.body - |it raises an exception + test 'f28QN5', %w( + | when an http-proxy + | receives JSON (but not a Hash) in its response.body + | it raises an exception ) do stub_saver_http('[]') ready_raises_exception('body is not JSON Hash') @@ -45,23 +40,23 @@ def self.id58_prefix # - - - - - - - - - - - - - - - - - - test 'QN6', %w[ - |when an http-proxy - |receives JSON-Hash with an exception key in its response.body - |it raises an exception - ] do + test 'f28QN6', %w( + | when an http-proxy + | receives JSON-Hash with an exception key in its response.body + | it raises an exception + ) do stub_saver_http('{"exception":42}') ready_raises_exception('42') end # - - - - - - - - - - - - - - - - - - test 'QN7', %w[ - |when an http-proxy - |receives JSON-Hash in its response.body - |which does not contain the requested method's key - |it raises an exception - ] do + test 'f28QN7', %w( + | when an http-proxy + | receives JSON-Hash in its response.body + | which does not contain the requested method's key + | it raises an exception + ) do stub_saver_http('{"wibble":42}') ready_raises_exception('body is missing ready? key') end @@ -78,4 +73,5 @@ def ready_raises_exception(expected_message) error = assert_raises(HttpJsonHash::ServiceError) { prober.ready } assert_equal expected_message, error.message end + end diff --git a/test/server/lib/coverage_metrics_limits.rb b/test/server/lib/coverage_metrics_limits.rb index 4a700d81..ed84f387 100644 --- a/test/server/lib/coverage_metrics_limits.rb +++ b/test/server/lib/coverage_metrics_limits.rb @@ -3,7 +3,7 @@ def metrics [ [ nil ], - [ 'test.lines.total' , '<=', 545 ], + [ 'test.lines.total' , '<=', 521 ], [ 'test.lines.missed' , '<=', 0 ], [ 'test.branches.total' , '<=', 0 ], [ 'test.branches.missed', '<=', 0 ], diff --git a/test/server/lib/id58_test_base.rb b/test/server/lib/id58_test_base.rb index 48b9a4a4..1ef8a480 100644 --- a/test/server/lib/id58_test_base.rb +++ b/test/server/lib/id58_test_base.rb @@ -26,11 +26,11 @@ def initialize(arg) @@seen_ids = [] @@timings = {} - def self.test(id58_suffix, *lines, &test_block) + def self.test(id58, *lines, &test_block) src = test_block.source_location src_file = File.basename(src[0]) src_line = src[1].to_s - id58 = checked_id58(id58_suffix, lines) + id58 = checked_id58(id58, lines) return unless @@args == [] || @@args.any? { |arg| id58.include?(arg) } name58 = lines.join(' ') @@ -49,7 +49,7 @@ def self.test(id58_suffix, *lines, &test_block) id58_teardown end } - name = "id58 '#{id58_suffix}',\n'#{name58}'" + name = "id58 '#{id58}',\n'#{name58}'" define_method("test_\n#{name}".to_sym, &execute_around) end @@ -77,25 +77,15 @@ def self.id58?(arg) arg.chars.all? { |chr| ID58_ALPHABET.include?(chr) } end - def self.checked_id58(id58_suffix, lines) - method = 'def self.id58_prefix' - pointer = "#{' ' * method.index('.')}!" - pointee = ['', pointer, method, '', ''].join("\n") - pointer = "\n\n#{pointer}" - raise "#{pointer}missing#{pointee}" unless respond_to?(:id58_prefix) - raise "#{pointer}empty#{pointee}" if id58_prefix == '' - raise "#{pointer}not id58#{pointee}" unless id58?(id58_prefix) - - method = "test '#{id58_suffix}'," + def self.checked_id58(id58, lines) + method = "test '#{id58}'," pointer = "#{' ' * method.index("'")}!" proposition = lines.join(' ') pointee = ['', pointer, method, "'#{proposition}'", '', ''].join("\n") - id58 = id58_prefix + id58_suffix pointer = "\n\n#{pointer}" - raise "#{pointer}empty#{pointee}" if id58_suffix == '' - raise "#{pointer}not id58#{pointee}" unless id58?(id58_suffix) + raise "#{pointer}empty#{pointee}" if id58 == '' + raise "#{pointer}not id58#{pointee}" unless id58?(id58) raise "#{pointer}duplicate#{pointee}" if @@seen_ids.include?(id58) - raise "#{pointer}overlap#{pointee}" if id58_prefix[-2..] == id58_suffix[0..1] @@seen_ids << id58 id58 diff --git a/test/server/prober_test.rb b/test/server/prober_test.rb index 4e4f3445..ead89ee0 100644 --- a/test/server/prober_test.rb +++ b/test/server/prober_test.rb @@ -4,19 +4,16 @@ require 'ostruct' class ProberTest < DifferTestBase - def self.id58_prefix - '198' - end - test '601', %w[alive] do + test '198601', %w[alive] do assert true?(prober.alive) end - test '603', %w[ready] do + test '198603', %w[ready] do assert true?(prober.ready) end - test '604', %w[ + test '198604', %w[ |when saver http-proxy is not ready |then ready? is false ] do @@ -24,7 +21,7 @@ def self.id58_prefix assert false?(prober.ready) end - test '191', %w[sha] do + test '198191', %w[sha] do sha = prober.sha assert_equal 40, sha.size sha.each_char do |ch| @@ -41,4 +38,5 @@ def true?(arg) def false?(arg) arg.instance_of?(FalseClass) end + end diff --git a/test/server/utf8_clean_test.rb b/test/server/utf8_clean_test.rb index 352e5cd2..26092e7d 100755 --- a/test/server/utf8_clean_test.rb +++ b/test/server/utf8_clean_test.rb @@ -4,15 +4,14 @@ require_app 'utf8_clean' class Utf8CleanTest < DifferTestBase - def self.id58_prefix - '3D9' - end - test '7FE', - 'cleaned string is not phased by invalid encodings' do + test '3D97FE', %w( + | cleaned string is not phased by invalid encodings + ) do bad_str = (100..1000).to_a.pack('c*').force_encoding('utf-8') refute bad_str.valid_encoding? good_str = Utf8.clean(bad_str) assert good_str.valid_encoding? end + end