|
| 1 | +// svctl |
| 2 | +// Copyright (C) 2015 Karol 'Kenji Takahashi' Woźniak |
| 3 | +// |
| 4 | +// Permission is hereby granted, free of charge, to any person obtaining |
| 5 | +// a copy of this software and associated documentation files (the "Software"), |
| 6 | +// to deal in the Software without restriction, including without limitation |
| 7 | +// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | +// and/or sell copies of the Software, and to permit persons to whom the |
| 9 | +// Software is furnished to do so, subject to the following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be included |
| 12 | +// in all copies or substantial portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 15 | +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 16 | +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 17 | +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 18 | +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 19 | +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE |
| 20 | +// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | + |
| 22 | +package main |
| 23 | + |
| 24 | +import ( |
| 25 | + "fmt" |
| 26 | + "testing" |
| 27 | + |
| 28 | + "github.com/peterh/liner" |
| 29 | +) |
| 30 | + |
| 31 | +func TestHelp(t *testing.T) { |
| 32 | + defs := []struct { |
| 33 | + action string |
| 34 | + nlines int |
| 35 | + }{ |
| 36 | + {"", 38}, |
| 37 | + {"up", 2}, |
| 38 | + {"down hup", 4}, |
| 39 | + {"help", 2}, |
| 40 | + {"help exit", 3}, |
| 41 | + } |
| 42 | + |
| 43 | + stdout := &stdout{} |
| 44 | + svctl := ctl{line: liner.NewLiner(), stdout: stdout} |
| 45 | + |
| 46 | + for _, def := range defs { |
| 47 | + svctl.Ctl(fmt.Sprintf("help %s", def.action)) |
| 48 | + |
| 49 | + n := stdout.Len() |
| 50 | + if n != def.nlines { |
| 51 | + t.Errorf("ERROR IN NLINES: `%d` != `%d` for `%s`", n, def.nlines, def.action) |
| 52 | + } |
| 53 | + |
| 54 | + stdout.Clear() |
| 55 | + } |
| 56 | + |
| 57 | + svctl.Ctl("help wrongaction") |
| 58 | + output := stdout.ReadString() |
| 59 | + expected := "wrongaction: unable to find action" |
| 60 | + if output != expected { |
| 61 | + t.Errorf("ERROR IN STATUS: `%s` != `%s` for `%s`", output, expected, "wrongaction") |
| 62 | + } |
| 63 | + |
| 64 | + svctl.line.Close() |
| 65 | +} |
0 commit comments