|
1 | 1 | package commands
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "github.com/chermehdi/egor/config" |
4 | 5 | "github.com/stretchr/testify/assert"
|
| 6 | + "os" |
| 7 | + "path" |
5 | 8 | "testing"
|
6 | 9 | )
|
7 | 10 |
|
@@ -51,6 +54,46 @@ func TestExtractTaskFromString(t *testing.T) {
|
51 | 54 | assert.Equal(t, task.Languages["java"].TaskClass, "CMinimizeTheInteger")
|
52 | 55 | }
|
53 | 56 |
|
54 |
| -func TestCurrentDirectory(t *testing.T) { |
55 |
| - //CreateDirectoryStructure(config.Task{}); |
| 57 | +func DeleteDir(dirPath string) { |
| 58 | + _ = os.RemoveAll(dirPath) |
| 59 | +} |
| 60 | + |
| 61 | +func TestCreateDirectoryStructure(t *testing.T) { |
| 62 | + task := config.Task{ |
| 63 | + Name: "Dummy task", |
| 64 | + Group: "Codeforces", |
| 65 | + Url: "http://codeforces.com/test", |
| 66 | + Interactive: false, |
| 67 | + MemoryLimit: 250, |
| 68 | + TimeLimit: 100, |
| 69 | + Tests: []config.TestCase{ |
| 70 | + {Input: "1", Output: "2"}, |
| 71 | + }, |
| 72 | + TestType: "", |
| 73 | + Input: config.IOType{"stdin"}, |
| 74 | + Output: config.IOType{"stdout"}, |
| 75 | + Languages: nil, |
| 76 | + } |
| 77 | + configuration := config.Config{ |
| 78 | + Lang: struct { |
| 79 | + Default string `yaml:"default"` |
| 80 | + }{Default: "cpp"}, |
| 81 | + ConfigFileName: "egor-meta.json", |
| 82 | + Version: "1.0", |
| 83 | + Author: "MaxHeap", |
| 84 | + } |
| 85 | + rootDir := os.TempDir() |
| 86 | + defer DeleteDir(rootDir) |
| 87 | + |
| 88 | + err := CreateDirectoryStructure(task, configuration, rootDir) |
| 89 | + assert.NoError(t, err) |
| 90 | + |
| 91 | + taskDir := path.Join(rootDir, task.Name) |
| 92 | + |
| 93 | + assert.FileExists(t, path.Join(taskDir, configuration.ConfigFileName)) |
| 94 | + assert.DirExists(t, path.Join(taskDir, "inputs")) |
| 95 | + assert.DirExists(t, path.Join(taskDir, "outputs")) |
| 96 | + assert.FileExists(t, path.Join(taskDir, "main.cpp")) |
| 97 | + assert.FileExists(t, path.Join(taskDir, "inputs", "test-0.in")) |
| 98 | + assert.FileExists(t, path.Join(taskDir, "outputs", "test-0.ans")) |
56 | 99 | }
|
0 commit comments