| 
									
										
										
										
											2023-07-18 19:29:41 +01:00
										 |  |  | #!/usr/bin/env bash
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Description: Validate that the number of directories in the output directory is as expected. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Arguments: | 
					
						
							|  |  |  | #   - $1: The expected number of directories in the output directory. | 
					
						
							|  |  |  | #   - $2: Name of the output folder. This is used to determine the structured output path. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | set +e | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EXPECTED_NUM_DIRS=$1 | 
					
						
							|  |  |  | OUTPUT_FOLDER_NAME=$2 | 
					
						
							|  |  |  | SCRIPT_DIR=$(dirname "$(realpath "$0")") | 
					
						
							| 
									
										
										
										
											2023-11-13 12:42:19 -06:00
										 |  |  | OUTPUT_ROOT=${OUTPUT_ROOT:-$SCRIPT_DIR} | 
					
						
							|  |  |  | OUTPUT_DIR=$OUTPUT_ROOT/structured-output/$OUTPUT_FOLDER_NAME | 
					
						
							| 
									
										
										
										
											2023-07-18 19:29:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | NUMBER_OF_FOUND_DIRS="$(find "$OUTPUT_DIR" -type d -exec printf '.' \; | wc -c | xargs)" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-28 19:04:59 -07:00
										 |  |  | # Note: single brackets and "-ne" operator were necessary for evaluation in CI | 
					
						
							|  |  |  | if [ "$NUMBER_OF_FOUND_DIRS" -ne "$EXPECTED_NUM_DIRS" ]; then | 
					
						
							| 
									
										
										
										
											2023-12-18 23:48:21 -08:00
										 |  |  |   echo | 
					
						
							|  |  |  |   echo "$EXPECTED_NUM_DIRS directories were expected to be found." | 
					
						
							|  |  |  |   echo "$NUMBER_OF_FOUND_DIRS directories were found instead." | 
					
						
							|  |  |  |   echo "Name of the directories found:" | 
					
						
							|  |  |  |   find "$OUTPUT_DIR" -type d | 
					
						
							|  |  |  |   exit 1 | 
					
						
							| 
									
										
										
										
											2023-07-18 19:29:41 +01:00
										 |  |  | fi |