mirror of
				https://github.com/go-task/task.git
				synced 2025-10-30 23:58:01 +02:00 
			
		
		
		
	fix: interpolate includes taskfile and dir
This commit is contained in:
		
							
								
								
									
										34
									
								
								task_test.go
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								task_test.go
									
									
									
									
									
								
							| @@ -1059,6 +1059,40 @@ func TestIncludesInternal(t *testing.T) { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestIncludesInterpolation(t *testing.T) { | ||||
| 	const dir = "testdata/includes_interpolation" | ||||
| 	tests := []struct { | ||||
| 		name           string | ||||
| 		task           string | ||||
| 		expectedErr    bool | ||||
| 		expectedOutput string | ||||
| 	}{ | ||||
| 		{"include", "include", false, "includes_interpolation\n"}, | ||||
| 		{"include with dir", "include-with-dir", false, "included\n"}, | ||||
| 	} | ||||
|  | ||||
| 	for _, test := range tests { | ||||
| 		t.Run(test.name, func(t *testing.T) { | ||||
| 			var buff bytes.Buffer | ||||
| 			e := task.Executor{ | ||||
| 				Dir:    dir, | ||||
| 				Stdout: &buff, | ||||
| 				Stderr: &buff, | ||||
| 				Silent: true, | ||||
| 			} | ||||
| 			assert.NoError(t, e.Setup()) | ||||
|  | ||||
| 			err := e.Run(context.Background(), taskfile.Call{Task: test.task}) | ||||
| 			if test.expectedErr { | ||||
| 				assert.Error(t, err) | ||||
| 			} else { | ||||
| 				assert.NoError(t, err) | ||||
| 			} | ||||
| 			assert.Equal(t, test.expectedOutput, buff.String()) | ||||
| 		}) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestInternalTask(t *testing.T) { | ||||
| 	const dir = "testdata/internal_task" | ||||
| 	tests := []struct { | ||||
|   | ||||
| @@ -73,7 +73,7 @@ func Taskfile(readerNode *ReaderNode) (*taskfile.Taskfile, error) { | ||||
|  | ||||
| 	err = t.Includes.Range(func(namespace string, includedTask taskfile.IncludedTaskfile) error { | ||||
| 		if v >= 3.0 { | ||||
| 			tr := templater.Templater{Vars: &taskfile.Vars{}, RemoveNoValue: true} | ||||
| 			tr := templater.Templater{Vars: t.Vars, RemoveNoValue: true} | ||||
| 			includedTask = taskfile.IncludedTaskfile{ | ||||
| 				Taskfile:       tr.Replace(includedTask.Taskfile), | ||||
| 				Dir:            tr.Replace(includedTask.Dir), | ||||
|   | ||||
							
								
								
									
										10
									
								
								testdata/includes_interpolation/Taskfile.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								testdata/includes_interpolation/Taskfile.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| version: "3" | ||||
|  | ||||
| vars: | ||||
|   MODULE_NAME: included | ||||
|  | ||||
| includes: | ||||
|   include: './{{.MODULE_NAME}}/Taskfile.yml' | ||||
|   include-with-dir: | ||||
|     taskfile: './{{.MODULE_NAME}}/Taskfile.yml' | ||||
|     dir: '{{.MODULE_NAME}}' | ||||
							
								
								
									
										6
									
								
								testdata/includes_interpolation/included/Taskfile.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								testdata/includes_interpolation/included/Taskfile.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| version: "3" | ||||
|  | ||||
| tasks: | ||||
|   default: | ||||
|     cmds: | ||||
|       - basename $(pwd) | ||||
		Reference in New Issue
	
	Block a user