@@ -1120,153 +1120,6 @@ func Test_GetSystemFile(t *testing.T) {
11201120 }
11211121}
11221122
1123- // Test_WriteProjectFile verifies generation of project.script for both board and device cases
1124- func Test_WriteProjectFile (t * testing.T ) {
1125- t .Parallel ()
1126-
1127- type args struct {
1128- workDir string
1129- params BridgeParamType
1130- }
1131-
1132- // Use testing provided temp dir (placed outside repo), to avoid leaving artifacts in VCS.
1133- baseTmp := t .TempDir ()
1134-
1135- tests := []struct {
1136- name string
1137- args args
1138- wantSubstring []string // lines / substrings that must appear (case sensitive)
1139- wantErr bool
1140- }{
1141- {
1142- name : "board_STMicroelectronics_loadboard" ,
1143- args : args {workDir : filepath .Join (baseTmp , "board" ), params : BridgeParamType {
1144- BoardName : "NUCLEO-H743ZI" ,
1145- BoardVendor : "STMicroelectronics" ,
1146- Device : "STMicroelectronics::STM32H743ZITx" ,
1147- Compiler : "GCC" ,
1148- }},
1149- wantSubstring : []string {
1150- "loadboard NUCLEO-H743ZI allmodes" ,
1151- "project name STM32CubeMX" ,
1152- "project toolchain \" STM32CubeIDE\" " ,
1153- // path line contains OS specific path - only check prefix
1154- "project path " ,
1155- "SetCopyLibrary \" copy only\" " ,
1156- },
1157- wantErr : false ,
1158- },
1159- {
1160- name : "generic_device_load" ,
1161- args : args {workDir : filepath .Join (baseTmp , "device" ), params : BridgeParamType {
1162- BoardName : "" , // forces device path
1163- BoardVendor : "" , // not ST => use load <device>
1164- Device : "AcmeSemi::ACM32F103RB" ,
1165- Compiler : "AC6" ,
1166- }},
1167- wantSubstring : []string {
1168- // Device part after vendor should be used
1169- "load ACM32F103RB" ,
1170- "project toolchain \" MDK-ARM V5\" " ,
1171- },
1172- wantErr : false ,
1173- },
1174- {
1175- name : "generic_device_load_with_part_vendor_prefix" ,
1176- args : args {workDir : filepath .Join (baseTmp , "device_vendor_part" ), params : BridgeParamType {
1177- BoardName : "" ,
1178- BoardVendor : "" ,
1179- Device : "VendorX::STM32F4:SomePart" , // should extract STM32F4 before ':'
1180- Compiler : "GCC" ,
1181- }},
1182- wantSubstring : []string {
1183- "load STM32F4" ,
1184- "project toolchain \" STM32CubeIDE\" " ,
1185- },
1186- wantErr : false ,
1187- },
1188- {
1189- name : "generic_device_load_with_part_no_vendor" ,
1190- args : args {workDir : filepath .Join (baseTmp , "device_part_only" ), params : BridgeParamType {
1191- BoardName : "" ,
1192- BoardVendor : "" ,
1193- Device : "STM32G0:AnotherPart" , // no vendor prefix, split at ':'
1194- Compiler : "CLANG" ,
1195- }},
1196- wantSubstring : []string {
1197- "load STM32G0" ,
1198- "project toolchain \" STM32CubeIDE\" " ,
1199- },
1200- wantErr : false ,
1201- },
1202- {
1203- name : "unknown_compiler" ,
1204- args : args {workDir : filepath .Join (baseTmp , "bad" ), params : BridgeParamType {
1205- Device : "V::D123" ,
1206- Compiler : "UNKNOWN" , // triggers error in GetToolchain
1207- }},
1208- wantErr : true ,
1209- },
1210- }
1211-
1212- for _ , tt := range tests {
1213- tt := tt
1214- t .Run (tt .name , func (t * testing.T ) {
1215- t .Parallel ()
1216- // create workDir explicitly to ensure consistent path semantics
1217- if err := os .MkdirAll (tt .args .workDir , 0o755 ); err != nil {
1218- t .Fatalf ("failed to create temp workdir: %v" , err )
1219- }
1220- gotFile , err := WriteProjectFile (tt .args .workDir , tt .args .params )
1221- if (err != nil ) != tt .wantErr {
1222- t .Fatalf ("WriteProjectFile() error = %v, wantErr %v" , err , tt .wantErr )
1223- }
1224- if tt .wantErr {
1225- return
1226- }
1227-
1228- // Validate file path
1229- expectedPath := filepath .Join (tt .args .workDir , "project.script" )
1230- if gotFile != expectedPath {
1231- t .Errorf ("expected file path %s, got %s" , expectedPath , gotFile )
1232- }
1233-
1234- data , err := os .ReadFile (gotFile )
1235- if err != nil {
1236- t .Fatalf ("failed reading generated file: %v" , err )
1237- }
1238- content := string (data )
1239-
1240- // Normalize path separator for portable substring checks on Windows
1241- if runtime .GOOS == "windows" {
1242- content = strings .ReplaceAll (content , "\\ " , "/" )
1243- }
1244-
1245- for _ , sub := range tt .wantSubstring {
1246- if ! strings .Contains (content , sub ) {
1247- t .Errorf ("expected substring %q not found in generated content:\n %s" , sub , content )
1248- }
1249- }
1250-
1251- // Second run: calling again must overwrite the file (no duplicate lines expected)
1252- if ! tt .wantErr {
1253- _ , err2 := WriteProjectFile (tt .args .workDir , tt .args .params )
1254- if err2 != nil {
1255- t .Fatalf ("second WriteProjectFile() call failed: %v" , err2 )
1256- }
1257- data2 , _ := os .ReadFile (gotFile )
1258- content2 := string (data2 )
1259- if runtime .GOOS == "windows" {
1260- content2 = strings .ReplaceAll (content2 , "\\ " , "/" )
1261- }
1262- if content2 != content { // expect exactly same content after overwrite (ignoring path sep style)
1263- t .Errorf ("file content changed after second call; want identical\n Before:\n %s\n After:\n %s" , content , content2 )
1264- }
1265- }
1266- })
1267- }
1268- }
1269-
12701123// func Test_GetLinkerScripts(t *testing.T) {
12711124// t.Parallel()
12721125
0 commit comments