-
-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathcommand-line-arguments.lisp
More file actions
136 lines (133 loc) · 5.34 KB
/
command-line-arguments.lisp
File metadata and controls
136 lines (133 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
(defpackage :lem-tests/command-line-arguments
(:use :cl
:rove))
(in-package :lem-tests/command-line-arguments)
(defun command-line-arguments-equal (arg1 arg2)
(and (equal (lem-core::command-line-arguments-help arg2)
(lem-core::command-line-arguments-help arg1))
(equal (lem-core::command-line-arguments-debug arg2)
(lem-core::command-line-arguments-debug arg1))
(equal (lem-core::command-line-arguments-version arg2)
(lem-core::command-line-arguments-version arg1))
(equal (lem-core::command-line-arguments-without-init-file arg2)
(lem-core::command-line-arguments-without-init-file arg1))
(equal (lem-core::command-line-arguments-log-filename arg2)
(lem-core::command-line-arguments-log-filename arg1))
(equal (lem-core::command-line-arguments-interface arg2)
(lem-core::command-line-arguments-interface arg1))
(equal (lem-core::command-line-arguments-filenames arg2)
(lem-core::command-line-arguments-filenames arg1))))
(deftest parse-args-test
(ok (command-line-arguments-equal
(lem-core::parse-args '("foo"))
(lem-core::make-command-line-arguments
:filenames '("foo"))))
(ok (command-line-arguments-equal
(lem-core::parse-args '("foo" "bar"))
(lem-core::make-command-line-arguments
:filenames '("foo" "bar"))))
(ok (command-line-arguments-equal
(lem-core::parse-args '("foo" "bar" "-i" "ncurses"))
(lem-core::make-command-line-arguments
:filenames '("foo" "bar")
:interface :ncurses)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("-i" "ncurses" "foo" "bar"))
(lem-core::make-command-line-arguments
:filenames '("foo" "bar")
:interface :ncurses)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("foo" "-i" "ncurses" "bar"))
(lem-core::make-command-line-arguments
:filenames '("foo" "bar")
:interface :ncurses)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("-i" "ncurses"))
(lem-core::make-command-line-arguments
:filenames '()
:interface :ncurses)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("-h"))
(lem-core::make-command-line-arguments
:filenames '()
:help t)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("--help"))
(lem-core::make-command-line-arguments
:filenames '()
:help t)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("-h" "foo"))
(lem-core::make-command-line-arguments
:filenames '("foo")
:help t)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("--debug"))
(lem-core::make-command-line-arguments
:filenames '()
:debug t)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("--debug" "foo"))
(lem-core::make-command-line-arguments
:filenames '("foo")
:debug t)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("-v"))
(lem-core::make-command-line-arguments
:filenames '()
:version t)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("--version"))
(lem-core::make-command-line-arguments
:filenames '()
:version t)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("-q"))
(lem-core::make-command-line-arguments
:filenames '()
:without-init-file t)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("--without-init-file"))
(lem-core::make-command-line-arguments
:filenames '()
:without-init-file t)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("--log-filename" "test.log"))
(lem-core::make-command-line-arguments
:filenames '()
:log-filename "test.log")))
(ok (command-line-arguments-equal
(lem-core::parse-args '("--log-filename" "test.log" "foo.txt"))
(lem-core::make-command-line-arguments
:filenames '("foo.txt")
:log-filename "test.log")))
(ok (command-line-arguments-equal
(lem-core::parse-args '("-i" "sdl2"))
(lem-core::make-command-line-arguments
:filenames '()
:interface :sdl2)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("--interface" "sdl2"))
(lem-core::make-command-line-arguments
:filenames '()
:interface :sdl2)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("--debug" "--without-init-file" "foo.txt"))
(lem-core::make-command-line-arguments
:filenames '("foo.txt")
:debug t
:without-init-file t)))
(ok (command-line-arguments-equal
(lem-core::parse-args '("-h" "-v" "--debug"))
(lem-core::make-command-line-arguments
:filenames '()
:help t
:version t
:debug t))))
(deftest parse-args-error-test
(testing "missing argument for --log-filename"
(ok (signals (lem-core::parse-args '("--log-filename")) 'lem-core::command-line-arguments-error)))
(testing "missing argument for -i"
(ok (signals (lem-core::parse-args '("-i")) 'lem-core::command-line-arguments-error)))
(testing "missing argument for --interface"
(ok (signals (lem-core::parse-args '("--interface")) 'lem-core::command-line-arguments-error))))