| Your company has just invented the hottest new | | | | but allows you to easily edit files in the Darwin file |
| web server to hit the market. You created a killer | | | | system. |
| test plan in Adobe Illustrator with breathtaking | | | | Emacs running native under Mac OS X environment |
| diagrams of your test network environment on | | | | Emacs contains most of the features you will require |
| Macintosh G4 running Mac OS X. Wouldn't it be great | | | | for editing programs in the Darwin environment. But |
| if you could run tests from your Mac too? Well ... you | | | | Emacs can be difficult to use. The hidden keystroke |
| can! | | | | commands are particularly annoying. For example, you |
| If you haven't been introduced already, the Tool | | | | must use control (^)x^s to save a file. The |
| Command Language, Tcl, is a secret weapon used by | | | | Aqua-on-Emacs port does, however, provide a nice |
| large network hardware corporations to test their | | | | menu bar to assist you if you're not familiar with the |
| devices. It's an extremely flexible scripting language | | | | editing environment. |
| that has been ported to nearly every operating | | | | Now that you've set up your rootless environment |
| system in existence, and that now includes Mac OS | | | | and have your editor installed, we can fire up Tcl. |
| X. | | | | Tcl is an installed package on Mac OS X machines. |
| As wonderful as it is, Tcl isn't perfect all by itself. | | | | However, Apple didn't include Expect, or Tk (X11 tool |
| That's why I'm also going to discuss Expect, which is | | | | kit for Tcl). Don't ask why. Not a real problem though. |
| an extension of Tcl that allows interactive automation | | | | Michael Peters has provided an excellent port of |
| to your Tcl scripts. For instance, using Expect you | | | | Expect 5.32 which requires Tcl 8.4a2 -- a revision |
| can automate telnet sessions, database queries, and | | | | different from Apple's. You'll need to download and |
| file transfers. | | | | install these two compressed packages to start using |
| For some reason, Apple didn't include Expect in its | | | | Expect. |
| operating system release. Not to worry, Expect has | | | | The downloadable file is a StuffIt .hqx file. Once |
| been ported to Mac OS X, and I'll walk you through | | | | downloaded, the image decompresses to a |
| the install of this handy extension. | | | | mountable disk image. You will need to use the Disk |
| Utilities that you will need | | | | Copy utility in the Applications/Utilities folder to mount |
| First I'll introduce you to a few utilities that I | | | | the .img file. |
| recommend you install on your test network | | | | Mounting the Tcl and Expect images |
| workstation. Nearly everything is available on the Net | | | | The mounted image is an installation package that |
| -- most of it from those diligent code porters | | | | you will need to double-click in order to start the |
| involved with the open-source sourceforge.net | | | | installation. Remember, the new Tcl installation is |
| project. | | | | required for the Expect installation. |
| With the current economic trends, your manager will | | | | The Tcl 8.4a2 folder contents |
| be pleased to know that you set up an awesome | | | | Unfortunately, the Expect and Expect Tk (the |
| workstation using mainly open-source applications. | | | | graphical user interface and toolkit) portion of the |
| The focus here is creating an automated test | | | | package has yet to be tackled for Mac OS X. In a |
| environment running on Mac OS X. However, the | | | | network test environment, we can survive with |
| same concepts will apply to any Unix workstation -- | | | | command-line scripts. But I know how excited your |
| thanks, again, to open-source efforts. | | | | manager gets when you show them a GUI |
| Rootless X on Mac OS X | | | | application. If you were adventurous enough to port |
| To begin, I recommend that you install Rootless X. | | | | Expect Tk, or know where a working image is hiding, |
| Torrey Lyons has released a rootless version of | | | | please let us know in the O'Reilly TalkBack section |
| XFree86 for Mac OS X. I provided installation | | | | for this article. In the meantime, we're command-line |
| instructions for X on X in a previous O'Reilly article, | | | | constrained. |
| Installing XFree86 on Mac OS X . Torrey's rootless | | | | Invoking Tcl |
| XFree86 is available from sourceforge.net (X on X). | | | | Comment on this articleAfter having worked with |
| XFree86 will soon become indispensable as you put | | | | Michael's Tcl examples, let us know what you think or |
| together your test automation system. The fact that | | | | where you got stuck. |
| your Mac OS X machine is running rootless allows you | | | | Post your comments |
| to run the XFree86 desktop and the Mac OS X | | | | Tcl is a simplistic language that is string-based. You |
| desktop in the same window. Prior to this, you were | | | | can invoked Tcl by executing the command tclsh |
| required to toggle between the two desktop | | | | from your terminal or console window. A simple "Hello |
| environments. See Figure 1. | | | | World!" script looks like this: |
| The examples listed later in this article will also run in | | | | Spongebob # tclsh |
| the Mac OS X console window utility. But in my | | | | % set myString "Hello World!" |
| opinion, life is a lot easier using the X Windows | | | | Hello World! |
| environment with multiple terminal windows opened. | | | | % puts $myString |
| This feature comes in handy when you're testing | | | | Hello World! |
| multiple network devices simultaneously, such as in a | | | | This code snippet demonstrates how Tcl uses the |
| network system test environment. | | | | set command to assign the string value "Hello World!" |
| Emacs on Aqua | | | | to the variable myString. Assigning a "$" in front of |
| Many editors are now available for Unix | | | | the variable, myString, instructs the interpreter that |
| environments; the two most prevalent are vi and | | | | the script is going to reference the value contained |
| emacs. The Emacs-on-Aqua utility is a complementary | | | | there. In this example, the string value is "Hello |
| tool to run with the rootless XFree86 environment. | | | | World!". The puts command writes the value |
| The Emacs utility executes in Mac OS X environment | | | | referenced to the terminal window. |