Menu

[1b4e70]: / tests / cit-arduino.el  Maximize  Restore  History

Download this file

158 lines (128 with data), 5.2 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
;;; cit-arduino.el --- Arduino testing.
;;
;; Copyright (C) 2012, 2014 Eric M. Ludlam
;;
;; Author: Eric M. Ludlam <eric@siege-engine.com>
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;
;; Test suite for the EDE/Arduino project type. Don't run this test
;; if the arduino SDK isn't installed.
;;
;;; Code:
(require 'ede/arduino)
(condition-case nil
(require 'arduino-mode)
(error (condition-case nil
(load-file "~/lisp/arduino-mode.el")
(error nil))))
(defvar cit-integ-arduino-sketchdir
(expand-file-name "edeprojectarduino" cedet-integ-base)
"Root of arduino sketches during the execution of this test.")
(defvar cit-integ-arduino-preftext
(format "
serial.port=/dev/ttyBOGUS
sketchbook.path=%s
board=uno
" cit-integ-arduino-sketchdir)
"Text for the temporary preferences file we use to fake out ede-arduino.")
(defvar cit-integ-arduino-preffile
(expand-file-name "preferences.txt" cit-integ-arduino-sketchdir)
"Preferences file we will create to override the default.")
(defvar cit-integ-arduino-testsketch
(expand-file-name "testsketch" cit-integ-arduino-sketchdir)
"Test sketch directory.")
(defvar cit-integ-arduino-servolibtags
(list
(semantic-tag-new-include "Servo.h" t)
(semantic-tag-new-variable "myservo" "Servo")
)
"Tags that force the compiler to link in the Servo library.")
(defun cit-ede-arduino-test ()
"Test the EDE Arduino based project."
;; Check for the SDK
(if (or (not (ede-arduino-find-install))
(not (featurep 'arduino-mode)))
(if (not (ede-arduino-find-install))
(message "Cannot run Arduino tests without arduino SDK installed.")
(if (not (featurep 'arduino-mode))
(message "Cannot run Arduino tests without arduino-mode. Install in ~/lisp/arduino-mode.el")
))
(message "Using Arduino environment version %s." (ede-arduino-Arduino-Version))
;; Reset the preferences file.
(message "Arduino tests in: %S" cit-integ-arduino-sketchdir)
(cit-make-dir cit-integ-arduino-sketchdir)
(save-current-buffer
(find-file cit-integ-arduino-preffile)
(erase-buffer)
(insert cit-integ-arduino-preftext)
(save-buffer))
;; Force ede-arduino to investigate, and test that we read the
;; file correctly.
(setq ede-arduino-preferences-file cit-integ-arduino-preffile)
(let ((prefs (ede-arduino-sync)))
(if (and (string= (oref prefs board) "uno")
(string= (oref prefs port) "/dev/ttyBOGUS")
(string= (file-name-as-directory (oref prefs sketchbook))
(file-name-as-directory cit-integ-arduino-sketchdir)))
(message "Preferences Redirect success!")
(error "Preferences redirect read failed.")))
;; Create the sketch directory
(cit-make-dir cit-integ-arduino-testsketch)
;; Force the autoloader to detect in the new location.
(let* ((arduinoauto (object-assoc 'ede/arduino :file
ede-project-class-files))
(adm (oref arduinoauto proj-root-dirmatch))
(testfn (expand-file-name "foo.cpp" cit-integ-arduino-testsketch)))
;; Splice the new tmp pref file into the system.
(oset adm :fromconfig ede-arduino-preferences-file)
;; Clear the cache.
(slot-makeunbound adm 'configdatastash)
;; Try it out
(if (ede-do-dirmatch adm testfn)
(message "Arduino dirmatch slice success!")
(error "Arduino dirmatch splicing from:
%s
failed to find:
%s."
ede-arduino-preferences-file testfn))
)
;; Load in the sketch file.
(let* ((vers (ede-arduino-Arduino-Version))
(fn (expand-file-name (concat "testsketch."
(if (version< vers "1.0")
"pde"
"ino"))
cit-integ-arduino-testsketch)))
(cit-srecode-fill-with-stuff fn nil)
(revert-buffer t t);; Force EDE detection.
(unless (ede-arduino-project-p ede-object-root-project)
(error "Arduino EDE project failed to detect. Found:
%S" ede-object))
;; Try compiling the empty sketch.
(cit-compile-and-wait-using-ede-command)
;; Test the ability to identify libraries, and link them in
;; correctly via the Makefile.
(find-file fn)
(let ((foundtags (semantic-fetch-tags)))
;; The first tag is the setup fcn.
(semantic-go-to-tag (car foundtags))
(forward-char -1))
(cit-srecode-insert-taglist cit-integ-arduino-servolibtags)
;; Try compiling the empty sketch.
(cit-compile-and-wait-using-ede-command)
)))
(provide 'cit-arduino)
;;; cit-arduino.el ends here
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.