From 3c626cafd51f18301af25f3188d75cad70b39d17 Mon Sep 17 00:00:00 2001 From: Fedor Korotkiy Date: Thu, 13 Feb 2020 02:28:27 +0300 Subject: [PATCH] Fix --- .deadlines.yml | 2 +- tools/testtool/commands/deadlines.go | 21 +++++---------------- tools/testtool/commands/deadlines_test.go | 8 ++++++++ tools/testtool/commands/grade.go | 5 +++++ 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/.deadlines.yml b/.deadlines.yml index fd297eb..c185ed2 100644 --- a/.deadlines.yml +++ b/.deadlines.yml @@ -1,5 +1,5 @@ - group: Hello World - start: 13-02-2020 18:00 + start: 12-02-2020 18:00 deadline: 23-02-2020 23:59 tasks: - task: sum diff --git a/tools/testtool/commands/deadlines.go b/tools/testtool/commands/deadlines.go index 819d149..5765442 100644 --- a/tools/testtool/commands/deadlines.go +++ b/tools/testtool/commands/deadlines.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "path/filepath" "sort" + "strings" "time" "gopkg.in/yaml.v2" @@ -73,29 +74,17 @@ func findChangedTasks(d Deadlines, files []string) []string { tasks := map[string]struct{}{} for _, f := range files { - for { - dir, _ := filepath.Split(f) - if dir == "" { - break - } - - f = dir - } - - if f == "" { + components := strings.Split(f, string(filepath.Separator)) + if len(components) == 0 { continue } - group, task := d.FindTask(f) + _, task := d.FindTask(components[0]) if task == nil { continue } - if !group.IsOpen() { - continue - } - - tasks[f] = struct{}{} + tasks[task.Name] = struct{}{} } var l []string diff --git a/tools/testtool/commands/deadlines_test.go b/tools/testtool/commands/deadlines_test.go index 0ebc158..96f9192 100644 --- a/tools/testtool/commands/deadlines_test.go +++ b/tools/testtool/commands/deadlines_test.go @@ -15,3 +15,11 @@ func TestDeadlines(t *testing.T) { require.NotNil(t, sum) require.Equal(t, "sum", sum.Name) } + +func TestDetectChange(t *testing.T) { + d, err := loadDeadlines("../../../.deadlines.yml") + require.NoError(t, err) + + changed := findChangedTasks(d, []string{"sum/sum.go", "testtool/foo.go", "README.md"}) + require.Equal(t, []string{"sum"}, changed) +} diff --git a/tools/testtool/commands/grade.go b/tools/testtool/commands/grade.go index de4f3e6..0e4774e 100644 --- a/tools/testtool/commands/grade.go +++ b/tools/testtool/commands/grade.go @@ -35,6 +35,11 @@ func grade() error { var failed bool for _, task := range changedTasks { + group, _ := deadlines.FindTask(task) + if !group.IsOpen() { + log.Printf("skipping task %s: not released yet", task) + } + log.Printf("testing task %s", task) var testFailed bool