more aesthetic changes.
In particular, using a concrete enum instead of a string to avoid an unnecessary incomplete pattern-match, and remove superfluous comments. Signed-off-by: KtorZ <5680256+KtorZ@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									37f721ff06
								
							
						
					
					
						commit
						a7f4ecef9d
					
				|  | @ -83,6 +83,12 @@ enum AddModuleBy { | ||||||
|     Path(PathBuf), |     Path(PathBuf), | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | #[derive(Debug, Clone, Copy)] | ||||||
|  | enum Runnable { | ||||||
|  |     Test, | ||||||
|  |     Bench, | ||||||
|  | } | ||||||
|  | 
 | ||||||
| pub struct Project<T> | pub struct Project<T> | ||||||
| where | where | ||||||
|     T: EventListener, |     T: EventListener, | ||||||
|  | @ -471,28 +477,30 @@ where | ||||||
|                 seed, |                 seed, | ||||||
|                 times_to_run, |                 times_to_run, | ||||||
|             } => { |             } => { | ||||||
|  |                 let verbose = false; | ||||||
|  | 
 | ||||||
|                 let tests = |                 let tests = | ||||||
|                     self.collect_benchmarks(false, match_tests, exact_match, options.tracing)?; |                     self.collect_benchmarks(verbose, match_tests, exact_match, options.tracing)?; | ||||||
| 
 | 
 | ||||||
|                 if !tests.is_empty() { |                 if !tests.is_empty() { | ||||||
|                     self.event_listener.handle_event(Event::RunningBenchmarks); |                     self.event_listener.handle_event(Event::RunningBenchmarks); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 let tests = self.run_benchmarks(tests, seed, times_to_run); |                 let benchmarks = self.run_benchmarks(tests, seed, times_to_run); | ||||||
| 
 | 
 | ||||||
|                 let errors: Vec<Error> = tests |                 let errors: Vec<Error> = benchmarks | ||||||
|                     .iter() |                     .iter() | ||||||
|                     .filter_map(|e| { |                     .filter_map(|e| { | ||||||
|                         if e.is_success() { |                         if e.is_success() { | ||||||
|                             None |                             None | ||||||
|                         } else { |                         } else { | ||||||
|                             Some(Error::from_test_result(e, false)) |                             Some(Error::from_test_result(e, verbose)) | ||||||
|                         } |                         } | ||||||
|                     }) |                     }) | ||||||
|                     .collect(); |                     .collect(); | ||||||
| 
 | 
 | ||||||
|                 self.event_listener |                 self.event_listener | ||||||
|                     .handle_event(Event::FinishedBenchmarks { seed, tests }); |                     .handle_event(Event::FinishedBenchmarks { seed, benchmarks }); | ||||||
| 
 | 
 | ||||||
|                 if !errors.is_empty() { |                 if !errors.is_empty() { | ||||||
|                     Err(errors) |                     Err(errors) | ||||||
|  | @ -954,7 +962,7 @@ where | ||||||
| 
 | 
 | ||||||
|     fn collect_test_items( |     fn collect_test_items( | ||||||
|         &mut self, |         &mut self, | ||||||
|         kind: &str, // "test" or "bench"
 |         kind: Runnable, | ||||||
|         verbose: bool, |         verbose: bool, | ||||||
|         match_tests: Option<Vec<String>>, |         match_tests: Option<Vec<String>>, | ||||||
|         exact_match: bool, |         exact_match: bool, | ||||||
|  | @ -993,8 +1001,8 @@ where | ||||||
| 
 | 
 | ||||||
|             for def in checked_module.ast.definitions() { |             for def in checked_module.ast.definitions() { | ||||||
|                 let func = match (kind, def) { |                 let func = match (kind, def) { | ||||||
|                     ("test", Definition::Test(func)) => Some(func), |                     (Runnable::Test, Definition::Test(func)) => Some(func), | ||||||
|                     ("bench", Definition::Benchmark(func)) => Some(func), |                     (Runnable::Bench, Definition::Benchmark(func)) => Some(func), | ||||||
|                     _ => None, |                     _ => None, | ||||||
|                 }; |                 }; | ||||||
| 
 | 
 | ||||||
|  | @ -1049,19 +1057,18 @@ where | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             tests.push(match kind { |             tests.push(match kind { | ||||||
|                 "test" => Test::from_function_definition( |                 Runnable::Test => Test::from_function_definition( | ||||||
|                     &mut generator, |                     &mut generator, | ||||||
|                     test.to_owned(), |                     test.to_owned(), | ||||||
|                     module_name, |                     module_name, | ||||||
|                     input_path, |                     input_path, | ||||||
|                 ), |                 ), | ||||||
|                 "bench" => Test::from_benchmark_definition( |                 Runnable::Bench => Test::from_benchmark_definition( | ||||||
|                     &mut generator, |                     &mut generator, | ||||||
|                     test.to_owned(), |                     test.to_owned(), | ||||||
|                     module_name, |                     module_name, | ||||||
|                     input_path, |                     input_path, | ||||||
|                 ), |                 ), | ||||||
|                 _ => unreachable!("Invalid test kind"), |  | ||||||
|             }); |             }); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -1075,7 +1082,7 @@ where | ||||||
|         exact_match: bool, |         exact_match: bool, | ||||||
|         tracing: Tracing, |         tracing: Tracing, | ||||||
|     ) -> Result<Vec<Test>, Error> { |     ) -> Result<Vec<Test>, Error> { | ||||||
|         self.collect_test_items("test", verbose, match_tests, exact_match, tracing) |         self.collect_test_items(Runnable::Test, verbose, match_tests, exact_match, tracing) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn collect_benchmarks( |     fn collect_benchmarks( | ||||||
|  | @ -1085,7 +1092,7 @@ where | ||||||
|         exact_match: bool, |         exact_match: bool, | ||||||
|         tracing: Tracing, |         tracing: Tracing, | ||||||
|     ) -> Result<Vec<Test>, Error> { |     ) -> Result<Vec<Test>, Error> { | ||||||
|         self.collect_test_items("bench", verbose, match_tests, exact_match, tracing) |         self.collect_test_items(Runnable::Bench, verbose, match_tests, exact_match, tracing) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn run_tests( |     fn run_tests( | ||||||
|  | @ -1107,7 +1114,9 @@ where | ||||||
|                 Test::PropertyTest(property_test) => { |                 Test::PropertyTest(property_test) => { | ||||||
|                     property_test.run(seed, property_max_success, plutus_version) |                     property_test.run(seed, property_max_success, plutus_version) | ||||||
|                 } |                 } | ||||||
|                 Test::Benchmark(_) => unreachable!("Benchmarks cannot be run in PBT."), |                 Test::Benchmark(_) => { | ||||||
|  |                     unreachable!("found unexpected benchmark amongst collected tests.") | ||||||
|  |                 } | ||||||
|             }) |             }) | ||||||
|             .collect::<Vec<TestResult<(Constant, Rc<Type>), PlutusData>>>() |             .collect::<Vec<TestResult<(Constant, Rc<Type>), PlutusData>>>() | ||||||
|             .into_iter() |             .into_iter() | ||||||
|  |  | ||||||
|  | @ -50,7 +50,7 @@ pub enum Event { | ||||||
|     }, |     }, | ||||||
|     FinishedBenchmarks { |     FinishedBenchmarks { | ||||||
|         seed: u32, |         seed: u32, | ||||||
|         tests: Vec<TestResult<UntypedExpr, UntypedExpr>>, |         benchmarks: Vec<TestResult<UntypedExpr, UntypedExpr>>, | ||||||
|     }, |     }, | ||||||
|     WaitingForBuildDirLock, |     WaitingForBuildDirLock, | ||||||
|     ResolvingPackages { |     ResolvingPackages { | ||||||
|  |  | ||||||
|  | @ -39,8 +39,8 @@ impl EventListener for Json { | ||||||
|                 }); |                 }); | ||||||
|                 println!("{}", serde_json::to_string_pretty(&json_output).unwrap()); |                 println!("{}", serde_json::to_string_pretty(&json_output).unwrap()); | ||||||
|             } |             } | ||||||
|             Event::FinishedBenchmarks { tests, seed } => { |             Event::FinishedBenchmarks { benchmarks, seed } => { | ||||||
|                 let benchmark_results: Vec<_> = tests |                 let benchmark_results: Vec<_> = benchmarks | ||||||
|                     .into_iter() |                     .into_iter() | ||||||
|                     .filter_map(|test| { |                     .filter_map(|test| { | ||||||
|                         if let TestResult::BenchmarkResult(result) = test { |                         if let TestResult::BenchmarkResult(result) = test { | ||||||
|  |  | ||||||
|  | @ -224,9 +224,9 @@ impl EventListener for Terminal { | ||||||
|                     "...".if_supports_color(Stderr, |s| s.bold()) |                     "...".if_supports_color(Stderr, |s| s.bold()) | ||||||
|                 ); |                 ); | ||||||
|             } |             } | ||||||
|             Event::FinishedBenchmarks { tests, .. } => { |             Event::FinishedBenchmarks { benchmarks, .. } => { | ||||||
|                 for test in tests { |                 for bench in benchmarks { | ||||||
|                     if let TestResult::BenchmarkResult(result) = test { |                     if let TestResult::BenchmarkResult(result) = bench { | ||||||
|                         println!("{} {} ", result.bench.name.bold(), "BENCH".blue(),); |                         println!("{} {} ", result.bench.name.bold(), "BENCH".blue(),); | ||||||
|                         println!("  Memory: {} bytes", result.cost.mem); |                         println!("  Memory: {} bytes", result.cost.mem); | ||||||
|                         println!("  CPU: {} units", result.cost.cpu); |                         println!("  CPU: {} units", result.cost.cpu); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 KtorZ
						KtorZ