@@ -10,66 +10,43 @@ echo -e "${YELLOW}=====================================${NC}"
1010echo -e " ${YELLOW} Running All bash_ini_parser Tests ${NC} "
1111echo -e " ${YELLOW} =====================================${NC} \n"
1212
13- # First run the basic tests
14- echo -e " ${YELLOW} Running Basic Tests...${NC} "
15- bash tests/lib_ini_tests.sh
16-
17- BASIC_EXIT=$?
18-
19- # Then run the extended tests
20- echo -e " \n${YELLOW} Running Extended Tests...${NC} "
21- bash tests/lib_ini_extended_tests.sh
22-
23- EXTENDED_EXIT=$?
24-
25- # Now run the environment override tests
26- echo -e " \n${YELLOW} Running Environment Override Tests...${NC} "
27- bash tests/test_env_override.sh
28-
29- ENV_OVERRIDE_EXIT=$?
30-
31- # Now run the security tests
32- echo -e " \n${YELLOW} Running Security Tests...${NC} "
33- bash tests/lib_ini_security_tests.sh
34-
35- SECURITY_EXIT=$?
36-
37- # Now run the advanced features tests
38- echo -e " \n${YELLOW} Running Advanced Features Tests...${NC} "
39- bash tests/lib_ini_advanced_features_tests.sh
40-
41- ADVANCED_EXIT=$?
42-
43- # Now run the BOM support tests
44- echo -e " \n${YELLOW} Running BOM Support Tests...${NC} "
45- bash tests/lib_ini_bom_tests.sh
46-
47- BOM_EXIT=$?
48-
49- # Extract test counts from each test suite
50- BASIC_TOTAL=$( bash tests/lib_ini_tests.sh 2>&1 | grep -oP ' Total tests executed: \K\d+' || echo " 0" )
51- BASIC_PASSED=$( bash tests/lib_ini_tests.sh 2>&1 | grep -oP ' Tests passed: \K\d+' || echo " 0" )
52- BASIC_FAILED=$( bash tests/lib_ini_tests.sh 2>&1 | grep -oP ' Tests failed: \K\d+' || echo " 0" )
53-
54- EXTENDED_TOTAL=$( bash tests/lib_ini_extended_tests.sh 2>&1 | grep -oP ' Total extended tests executed: \K\d+' || echo " 0" )
55- EXTENDED_PASSED=$( bash tests/lib_ini_extended_tests.sh 2>&1 | grep -oP ' Tests passed: \K\d+' || echo " 0" )
56- EXTENDED_FAILED=$( bash tests/lib_ini_extended_tests.sh 2>&1 | grep -oP ' Tests failed: \K\d+' || echo " 0" )
57-
58- ENV_TOTAL=$( bash tests/test_env_override.sh 2>&1 | grep -oP ' Total environment override tests executed: \K\d+' || echo " 0" )
59- ENV_PASSED=$( bash tests/test_env_override.sh 2>&1 | grep -oP ' Tests passed: \K\d+' || echo " 0" )
60- ENV_FAILED=$( bash tests/test_env_override.sh 2>&1 | grep -oP ' Tests failed: \K\d+' || echo " 0" )
61-
62- SECURITY_TOTAL=$( bash tests/lib_ini_security_tests.sh 2>&1 | grep -oP ' Total security tests executed: \K\d+' || echo " 0" )
63- SECURITY_PASSED=$( bash tests/lib_ini_security_tests.sh 2>&1 | grep -oP ' Tests passed: \K\d+' || echo " 0" )
64- SECURITY_FAILED=$( bash tests/lib_ini_security_tests.sh 2>&1 | grep -oP ' Tests failed: \K\d+' || echo " 0" )
65-
66- ADVANCED_TOTAL=$( bash tests/lib_ini_advanced_features_tests.sh 2>&1 | grep -oP ' Total advanced features tests executed: \K\d+' || echo " 0" )
67- ADVANCED_PASSED=$( bash tests/lib_ini_advanced_features_tests.sh 2>&1 | grep -oP ' Tests passed: \K\d+' || echo " 0" )
68- ADVANCED_FAILED=$( bash tests/lib_ini_advanced_features_tests.sh 2>&1 | grep -oP ' Tests failed: \K\d+' || echo " 0" )
69-
70- BOM_TOTAL=$( bash tests/lib_ini_bom_tests.sh 2>&1 | grep -oP ' Total BOM tests executed: \K\d+' || echo " 0" )
71- BOM_PASSED=$( bash tests/lib_ini_bom_tests.sh 2>&1 | grep -oP ' Tests passed: \K\d+' || echo " 0" )
72- BOM_FAILED=$( bash tests/lib_ini_bom_tests.sh 2>&1 | grep -oP ' Tests failed: \K\d+' || echo " 0" )
13+ # Helper to run a test suite, capture output, and extract counts
14+ run_suite () {
15+ local suite_name=" $1 "
16+ local suite_cmd=" $2 "
17+ local total_pattern=" $3 "
18+
19+ echo -e " ${YELLOW} Running ${suite_name} ...${NC} "
20+ local output
21+ output=$( bash " $suite_cmd " 2>&1 )
22+ local exit_code=$?
23+ echo " $output "
24+
25+ # Extract counts from captured output
26+ local total passed failed
27+ total=$( echo " $output " | grep -oP " ${total_pattern} : \\ K\\ d+" || echo " 0" )
28+ passed=$( echo " $output " | grep -oP ' Tests passed: \K\d+' || echo " 0" )
29+ failed=$( echo " $output " | grep -oP ' Tests failed: \K\d+' || echo " 0" )
30+
31+ # Store results in global variables using nameref
32+ eval " ${suite_name// / _} _TOTAL=$total "
33+ eval " ${suite_name// / _} _PASSED=$passed "
34+ eval " ${suite_name// / _} _FAILED=$failed "
35+ eval " ${suite_name// / _} _EXIT=$exit_code "
36+ }
37+
38+ # Run all test suites (each only once)
39+ run_suite " BASIC" " tests/lib_ini_tests.sh" " Total tests executed"
40+ echo " "
41+ run_suite " EXTENDED" " tests/lib_ini_extended_tests.sh" " Total extended tests executed"
42+ echo " "
43+ run_suite " ENV" " tests/test_env_override.sh" " Total environment override tests executed"
44+ echo " "
45+ run_suite " SECURITY" " tests/lib_ini_security_tests.sh" " Total security tests executed"
46+ echo " "
47+ run_suite " ADVANCED" " tests/lib_ini_advanced_features_tests.sh" " Total advanced features tests executed"
48+ echo " "
49+ run_suite " BOM" " tests/lib_ini_bom_tests.sh" " Total BOM tests executed"
7350
7451# Calculate totals
7552TOTAL_TESTS=$(( BASIC_TOTAL + EXTENDED_TOTAL + ENV_TOTAL + SECURITY_TOTAL + ADVANCED_TOTAL + BOM_TOTAL))
@@ -88,16 +65,17 @@ echo -e "BOM support tests: ${BOM_TOTAL} executed, ${GREEN}${BOM_PASSED} passed
8865echo -e " ${YELLOW} -------------------------------------${NC} "
8966echo -e " Total: ${TOTAL_TESTS} executed, ${GREEN}${TOTAL_PASSED} passed${NC} , ${RED}${TOTAL_FAILED} failed${NC} "
9067
91- if [ $BASIC_EXIT -eq 0 ] && [ $EXTENDED_EXIT -eq 0 ] && [ $ENV_OVERRIDE_EXIT -eq 0 ] && [ $SECURITY_EXIT -eq 0 ] && [ $ADVANCED_EXIT -eq 0 ] && [ $BOM_EXIT -eq 0 ]; then
68+ if [ $BASIC_EXIT -eq 0 ] && [ $EXTENDED_EXIT -eq 0 ] && [ $ENV_EXIT -eq 0 ] && [ $SECURITY_EXIT -eq 0 ] && [ $ADVANCED_EXIT -eq 0 ] && [ $BOM_EXIT -eq 0 ]; then
9269 echo -e " \n${GREEN} ALL TESTS PASSED!${NC} "
9370 exit 0
9471else
9572 echo -e " \n${RED} SOME TESTS FAILED!${NC} "
9673 [ $BASIC_EXIT -ne 0 ] && echo -e " ${RED} Basic tests failed.${NC} "
9774 [ $EXTENDED_EXIT -ne 0 ] && echo -e " ${RED} Extended tests failed.${NC} "
98- [ $ENV_OVERRIDE_EXIT -ne 0 ] && echo -e " ${RED} Environment override tests failed.${NC} "
75+ [ $ENV_EXIT -ne 0 ] && echo -e " ${RED} Environment override tests failed.${NC} "
9976 [ $SECURITY_EXIT -ne 0 ] && echo -e " ${RED} Security tests failed.${NC} "
10077 [ $ADVANCED_EXIT -ne 0 ] && echo -e " ${RED} Advanced features tests failed.${NC} "
10178 [ $BOM_EXIT -ne 0 ] && echo -e " ${RED} BOM support tests failed.${NC} "
10279 exit 1
103- fi
80+ fi
81+
0 commit comments