-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental way to expose tasks, adding them to global scope.
- Loading branch information
Showing
11 changed files
with
224 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
Feature: Exposing imported package tasks so they can be invoked without the alias. | ||
|
||
Background: | ||
Given I'm in project dir | ||
|
||
|
||
Scenario: Expose tasks | ||
Given file ./Oyafile containing | ||
""" | ||
Project: main | ||
""" | ||
And file ./project1/Oyafile containing | ||
""" | ||
Values: | ||
foo: project1 | ||
echo: | | ||
echo "project1" | ||
""" | ||
And file ./project2/Oyafile containing | ||
""" | ||
Import: | ||
p: /project1 | ||
Expose: p | ||
""" | ||
And I'm in the ./project2 dir | ||
When I run "oya run echo" | ||
Then the command succeeds | ||
And the command outputs | ||
""" | ||
project1 | ||
""" | ||
|
||
@current | ||
Scenario: Never overwrite existing an task when exposing tasks | ||
Given file ./Oyafile containing | ||
""" | ||
Project: main | ||
""" | ||
And file ./project1/Oyafile containing | ||
""" | ||
Values: | ||
foo: project1 | ||
echo: | | ||
echo "project1" | ||
""" | ||
And file ./project2/Oyafile containing | ||
""" | ||
Import: | ||
p: /project1 | ||
Expose: p | ||
echo: | | ||
echo "project2" | ||
""" | ||
And I'm in the ./project2 dir | ||
When I run "oya run echo" | ||
Then the command succeeds | ||
And the command outputs | ||
""" | ||
project2 | ||
""" | ||
|
||
|
||
# TODO: Show as aliases when listing tasks. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package task | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/tooploox/oya/pkg/template" | ||
) | ||
|
||
type MockTask struct{} | ||
|
||
func (MockTask) Exec(workDir string, args []string, scope template.Scope, stdout, stderr io.Writer) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package task | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/tooploox/oya/pkg/template" | ||
) | ||
|
||
type reference struct { | ||
task Task | ||
} | ||
|
||
func NewReference(task Task) Task { | ||
return reference{ | ||
task: task, | ||
} | ||
} | ||
|
||
func (r reference) Exec(workDir string, args []string, scope template.Scope, stdout, stderr io.Writer) error { | ||
return r.task.Exec(workDir, args, scope, stdout, stderr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package task_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/tooploox/oya/pkg/task" | ||
"github.com/tooploox/oya/pkg/types" | ||
tu "github.com/tooploox/oya/testutil" | ||
) | ||
|
||
func TestTable_Expose(t *testing.T) { | ||
tt := task.NewTable() | ||
|
||
globalName := task.Name("task") | ||
aliasedName := globalName.Aliased("alias") | ||
tt.AddTask(aliasedName, task.MockTask{}) | ||
|
||
tt.Expose(types.Alias("alias")) | ||
|
||
_, ok := tt.LookupTask(aliasedName) | ||
tu.AssertTrue(t, ok, "Aliased task not found") | ||
_, ok = tt.LookupTask(globalName) | ||
tu.AssertTrue(t, ok, "Global task not found") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters