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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
(use-modules (ice-9 receive))
(load-from-path "env.scm")
(putenv (string-append "LEPTON_SHELL" "=" lepton-shell))
(define cwd (getcwd))
(define *testdir* (build-filename (getcwd) "cli-tmp"))
;;; Setup/teardown directories/files needed by tests.
(define (test-setup)
(mkdir *testdir*)
(chdir *testdir*))
(define (test-teardown)
(chdir cwd)
(system* "rm" "-rf" *testdir*))
(define help-string "Usage: lepton-cli [OPTION...] COMMAND [ARGS ...]")
(define run-help-string "Run `lepton-cli --help' for more information.")
;;; Test lepton-cli without args.
(test-begin "lepton-cli")
(receive (<status> <stdout> <stderr>)
(command-values lepton-cli)
(test-eq EXIT_FAILURE <status>)
(test-assert (string-contains <stderr> "ERROR: You must specify a command to run."))
(test-assert (string-contains <stderr> run-help-string)))
(test-end "lepton-cli")
;;; Test it with --no-rcfiles but without any command.
(test-begin "lepton-cli --no-rcfiles")
(receive (<status> <stdout> <stderr>)
(command-values lepton-cli "--no-rcfiles")
(test-eq EXIT_FAILURE <status>)
(test-assert (string-contains <stderr> "ERROR: You must specify a command to run."))
(test-assert (string-contains <stderr> run-help-string)))
(test-group-with-cleanup "lepton-cli --no-rcfiles export"
(test-setup)
;; That environment variable is set in Makefile. Unset it
;; temporarily to facilitate testing. Warning: it may create
;; unintended consequences if there's something weird in the
;; user or system gafrc.
(unsetenv "LEPTON_INHIBIT_RC_FILES")
;; Create gafrc file with known contents.
(string->file "(display \"gafrc is loaded\")\n" "gafrc")
;; First, check if the command in gafrc works.
(receive (<status> <stdout> <stderr>)
(command-values lepton-cli "export")
(test-eq EXIT_FAILURE <status>)
(test-assert (string-contains <stdout> "gafrc is loaded")))
;; Now, disable loading of RC files.
(receive (<status> <stdout> <stderr>)
(command-values lepton-cli "--no-rcfiles" "export")
(test-eq EXIT_FAILURE <status>)
(test-assert (not (string-contains <stdout> "gafrc is loaded"))))
;; Restore the environment variable to not break other tests.
(putenv "LEPTON_INHIBIT_RC_FILES=yes")
;; Clean up.
(test-teardown))
(test-group-with-cleanup "lepton-cli --no-rcfiles shell"
(test-setup)
;; That environment variable is set in Makefile. Unset it
;; temporarily to facilitate testing. Warning: it may create
;; unintended consequences if there's something weird in the
;; user or system gafrc. The tests can also break if your
;; installation is broken because system-gafrc depends on it.
(unsetenv "LEPTON_INHIBIT_RC_FILES")
;; Create gafrc file with known contents.
(string->file "(display \"gafrc is loaded\")\n" "gafrc")
;; First, check if the command in gafrc works.
(receive (<status> <stdout> <stderr>)
(command-values lepton-cli "shell" "-c" "(exit 10)")
(test-eq 10 <status>)
(test-assert (string-contains <stdout> "gafrc is loaded")))
;; Now, disable loading of RC files.
(receive (<status> <stdout> <stderr>)
(command-values lepton-cli "--no-rcfiles" "shell" "-c" "(exit 10)")
(test-eq 10 <status>)
(test-assert (not (string-contains <stdout> "gafrc is loaded"))))
;; Restore the environment variable to not break other tests.
(putenv "LEPTON_INHIBIT_RC_FILES=yes")
;; Clean up.
(test-teardown))
(test-end "lepton-cli --no-rcfiles")
(test-begin "lepton-cli -h")
(receive (<status> <stdout> <stderr>)
(command-values lepton-cli "-h")
(test-eq EXIT_SUCCESS <status>)
(test-assert (string-contains <stdout> help-string)))
(test-end "lepton-cli -h")
(test-begin "lepton-cli --help")
(receive (<status> <stdout> <stderr>)
(command-values lepton-cli "--help")
(test-eq EXIT_SUCCESS <status>)
(test-assert (string-contains <stdout> help-string)))
(test-end "lepton-cli --help")
(test-begin "lepton-cli -V")
(receive (<status> <stdout> <stderr>)
(command-values lepton-cli "-V")
(test-eq EXIT_SUCCESS <status>)
(test-assert (string-contains <stdout> "Lepton EDA"))
(test-assert (string-contains <stdout> "Copyright"))
(test-assert (string-contains <stdout> "There is NO WARRANTY")))
(test-end "lepton-cli -V")
(test-begin "lepton-cli --version")
(receive (<status> <stdout> <stderr>)
(command-values lepton-cli "--version")
(test-eq EXIT_SUCCESS <status>)
(test-assert (string-contains <stdout> "Lepton EDA"))
(test-assert (string-contains <stdout> "Copyright"))
(test-assert (string-contains <stdout> "There is NO WARRANTY")))
(test-end "lepton-cli --version")
(test-begin "lepton-cli wrong command")
(receive (<status> <stdout> <stderr>)
(command-values lepton-cli "wrong" "command")
(test-eq EXIT_FAILURE <status>)
(test-assert (string-contains <stderr> "Unrecognised command"))
(test-assert (string-contains <stderr> run-help-string)))
(test-end "lepton-cli wrong command")
|