1
+ #! /usr/bin/env bash
2
+ set -ex
3
+
4
+ # Test script for FPM features functionality
5
+ # Usage: ./test_features.sh [fpm_executable]
6
+ # Note: This script should be run from the repo root or integrated into run_tests.sh
7
+
8
+ if [ " $1 " ]; then
9
+ fpm=" $1 "
10
+ else
11
+ # Default to the fpm passed from run_tests.sh or system fpm
12
+ fpm=" ${fpm:- fpm} "
13
+ fi
14
+
15
+ echo " Testing FPM features functionality"
16
+
17
+ echo " === Testing features_demo package ==="
18
+
19
+ # Test 1: Basic features - debug feature
20
+ pushd " features_demo"
21
+ echo " Test 1: Basic debug feature"
22
+ rm -rf build
23
+ " $fpm " run --features debug | tee output.txt
24
+ grep -q " DEBUG mode enabled" output.txt
25
+ grep -q " ✓ DEBUG mode enabled" output.txt
26
+ echo " ✓ Debug feature works"
27
+
28
+ # Test 2: Profile usage - development profile (includes debug)
29
+ echo " Test 2: Development profile (debug feature)"
30
+ rm -rf build
31
+ " $fpm " run --profile development --target features_demo | tee output.txt
32
+ grep -q " DEBUG mode enabled" output.txt
33
+ echo " ✓ Development profile works"
34
+
35
+ # Test 3: Multiple features
36
+ echo " Test 3: Multiple features (debug + openmp)"
37
+ rm -rf build
38
+ " $fpm " run --features debug,openmp --target features_demo | tee output.txt
39
+ grep -q " DEBUG mode enabled" output.txt
40
+ grep -q " OpenMP support enabled" output.txt
41
+ echo " ✓ Multiple features work"
42
+
43
+ # Test 4: Feature-specific executable (debug_demo only available with debug feature)
44
+ echo " Test 4: Feature-specific executable"
45
+ rm -rf build
46
+ " $fpm " run --feature debug --target debug_demo | tee output.txt
47
+ grep -q " Debug Demo Program" output.txt
48
+ grep -q " Debug mode: ON" output.txt
49
+ echo " ✓ Feature-specific executable works"
50
+
51
+ # Test 5: Profile with multiple features - production profile (release + openmp)
52
+ echo " Test 5: Production profile (release + openmp)"
53
+ rm -rf build
54
+ " $fpm " run --profile production --target features_demo | tee output.txt
55
+ grep -q " RELEASE mode enabled" output.txt
56
+ grep -q " OpenMP support enabled" output.txt
57
+ # Should NOT have debug
58
+ ! grep -q " DEBUG mode enabled" output.txt
59
+ echo " ✓ Production profile works"
60
+
61
+ # Test 6: No features - baseline behavior
62
+ echo " Test 6: No features (baseline)"
63
+ rm -rf build
64
+ " $fpm " run --target features_demo | tee output.txt
65
+ # Should have neither DEBUG nor RELEASE without explicit features
66
+ ! grep -q " DEBUG mode enabled" output.txt || true
67
+ ! grep -q " RELEASE mode enabled" output.txt || true
68
+ grep -q " Features: NONE" output.txt || grep -q " Demo completed successfully" output.txt
69
+ echo " ✓ Baseline (no features) works"
70
+
71
+ # Test 7: Build listing with features
72
+ echo " Test 7: Build listing with features"
73
+ rm -rf build
74
+ " $fpm " build --feature debug --list | tee build_list.txt
75
+ grep -q " debug_demo" build_list.txt
76
+ grep -q " features_demo" build_list.txt
77
+ echo " ✓ Build listing with features works"
78
+
79
+ # Test 8: Error handling - invalid feature
80
+ echo " Test 8: Error handling for invalid feature"
81
+ rm -rf build
82
+ if " $fpm " run --feature nonexistent --target features_demo 2>&1 | grep -q " undefined feature" ; then
83
+ echo " ✓ Correctly rejected invalid feature"
84
+ else
85
+ echo " ERROR: Should reject invalid feature" && exit 1
86
+ fi
87
+
88
+ # Test 9: Error handling - invalid profile
89
+ echo " Test 9: Error handling for invalid profile"
90
+ rm -rf build
91
+ if " $fpm " run --profile nonexistent --target features_demo 2>&1 | grep -q " undefined profile" ; then
92
+ echo " ✓ Correctly rejected invalid profile"
93
+ else
94
+ echo " ERROR: Should reject invalid profile" && exit 1
95
+ fi
96
+
97
+ # Test 10: Features and profile mutual exclusion
98
+ echo " Test 10: Features and profile mutual exclusion"
99
+ rm -rf build
100
+ if " $fpm " run --feature debug --profile development --target features_demo 2>&1 | grep -q " cannot specify both" ; then
101
+ echo " ✓ Correctly rejected features + profile combination"
102
+ else
103
+ echo " ERROR: Should reject features + profile combination" && exit 1
104
+ fi
105
+
106
+ # Cleanup
107
+ rm -rf build output.txt build_list.txt
108
+ popd
109
+
110
+ echo " === Testing features_with_dependency package ==="
111
+
112
+ # Test dependency features
113
+ pushd " features_with_dependency"
114
+
115
+ # Test 11: No features - should show NONE for both local and dependency
116
+ echo " Test 11: Dependency package without features"
117
+ rm -rf build
118
+ " $fpm " run | tee output.txt
119
+ grep -q " NONE - no local features active" output.txt
120
+ grep -q " Features: NONE" output.txt
121
+ echo " ✓ Dependency package baseline works"
122
+
123
+ # Test 12: Debug dependency feature
124
+ echo " Test 12: Debug dependency feature"
125
+ rm -rf build
126
+ " $fpm " run --features with_feat_debug | tee output.txt
127
+ grep -q " WITH_DEBUG_DEPENDENCY" output.txt
128
+ grep -q " DEBUG mode enabled" output.txt
129
+ echo " ✓ Debug dependency feature works"
130
+
131
+ # Test 13: Release dependency feature
132
+ echo " Test 13: Release dependency feature"
133
+ rm -rf build
134
+ " $fpm " run --features with_feat_release | tee output.txt
135
+ grep -q " WITH_RELEASE_DEPENDENCY" output.txt
136
+ grep -q " RELEASE mode enabled" output.txt
137
+ echo " ✓ Release dependency feature works"
138
+
139
+ # Test 14: Multi dependency feature
140
+ echo " Test 14: Multi dependency feature"
141
+ rm -rf build
142
+ " $fpm " run --features with_feat_multi | tee output.txt
143
+ grep -q " WITH_MULTI_DEPENDENCY" output.txt
144
+ grep -q " DEBUG mode enabled" output.txt
145
+ grep -q " MPI support enabled" output.txt
146
+ echo " ✓ Multi dependency feature works"
147
+
148
+ # Test 15: Profile with dependency features
149
+ echo " Test 15: Debug dependency profile"
150
+ rm -rf build
151
+ " $fpm " run --profile debug_dep | tee output.txt
152
+ grep -q " WITH_DEBUG_DEPENDENCY" output.txt
153
+ grep -q " DEBUG mode enabled" output.txt
154
+ echo " ✓ Debug dependency profile works"
155
+
156
+ # Cleanup
157
+ rm -rf build output.txt
158
+ popd
159
+
160
+ echo " All FPM features tests passed!"
0 commit comments