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