mirror of
				https://gitea.invidious.io/iv-org/shard-ameba.git
				synced 2024-08-15 00:53:29 +00:00 
			
		
		
		
	Add test spec covering the loop { … } block to Lint/SharedVarInFiber rule specs
				
					
				
			This commit is contained in:
		
							parent
							
								
									57898fd797
								
							
						
					
					
						commit
						1feb5c279b
					
				
					 1 changed files with 19 additions and 1 deletions
				
			
		|  | @ -39,7 +39,7 @@ module Ameba::Rule::Lint | ||||||
|         CRYSTAL |         CRYSTAL | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     it "reports if there is a shared var in spawn" do |     it "reports if there is a shared var in spawn (while)" do | ||||||
|       source = expect_issue subject, <<-CRYSTAL |       source = expect_issue subject, <<-CRYSTAL | ||||||
|         i = 0 |         i = 0 | ||||||
|         while i < 10 |         while i < 10 | ||||||
|  | @ -56,6 +56,24 @@ module Ameba::Rule::Lint | ||||||
|       expect_no_corrections source |       expect_no_corrections source | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  |     it "reports if there is a shared var in spawn (loop)" do | ||||||
|  |       source = expect_issue subject, <<-CRYSTAL | ||||||
|  |         i = 0 | ||||||
|  |         loop do | ||||||
|  |           break if i >= 10 | ||||||
|  |           spawn do | ||||||
|  |             puts(i) | ||||||
|  |                # ^ error: Shared variable `i` is used in fiber | ||||||
|  |           end | ||||||
|  |           i += 1 | ||||||
|  |         end | ||||||
|  | 
 | ||||||
|  |         Fiber.yield | ||||||
|  |         CRYSTAL | ||||||
|  | 
 | ||||||
|  |       expect_no_corrections source | ||||||
|  |     end | ||||||
|  | 
 | ||||||
|     it "reports reassigned reference to shared var in spawn" do |     it "reports reassigned reference to shared var in spawn" do | ||||||
|       source = expect_issue subject, <<-CRYSTAL |       source = expect_issue subject, <<-CRYSTAL | ||||||
|         channel = Channel(String).new |         channel = Channel(String).new | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue