# HG changeset patch
# User Jeroen Demeyer <jdemeyer@cage.ugent.be>
# Date 1325586347 3600
# Node ID 3b86f642a312bdc7deae4212fc816eb60003fc0b
# Parent b72663c760492cc8c360d328a6d370c8f88d2069
Test sagerun
diff git a/sage/tests/cmdline.py b/sage/tests/cmdline.py
a

b


3  3  do something. 
4  4  
5  5  We test the following command line options: 
 6  
 7  test.py 
 8  /path/to/test.py 
 9  test.sage 
 10  /path/to/test.sage 
6  11  advanced 
7  12  branch 
8  13  c 
… 
… 

81  86  ... 
82  87  RuntimeError: timeout in test_executable() 
83  88  
84   TESTS:: 
 89  TESTS: 
 90  
 91  Run Sage itself with various options:: 
85  92  
86  93  sage: (out, err, ret) = test_executable(["sage"]) 
87  94  sage: out.find(version()) >= 0 
… 
… 

112  119  0 
113  120  
114  121  sage: (out, err, ret) = test_executable(["sage", "c", "print 3^33"]) 
115   sage: out.find("5559060566555523\n") >= 0 
116   True 
 122  sage: print out 
 123  5559060566555523 
117  124  sage: err 
118  125  '' 
119  126  sage: ret 
120  127  0 
121  128  
122  129  sage: (out, err, ret) = test_executable(["sage", "min", "c", "print 3^33"]) 
123   sage: out.find("5559060566555523\n") >= 0 
 130  sage: print out 
 131  5559060566555523 
 132  sage: err 
 133  '' 
 134  sage: ret 
 135  0 
 136  
 137  sage: (out, err, ret) = test_executable(["sage", "startuptime"]) 
 138  sage: out.find("sage.all: ") >= 0 
124  139  True 
125  140  sage: err 
126  141  '' 
127  142  sage: ret 
128  143  0 
 144  
 145  Test help:: 
129  146  
130  147  sage: (out, err, ret) = test_executable(["sage", "h"]) 
131  148  sage: out.find("Optional arguments:") >= 0 
… 
… 

151  168  sage: ret 
152  169  0 
153  170  
 171  Basic information about the Sage installation:: 
 172  
154  173  sage: (out, err, ret) = test_executable(["sage", "v"]) 
155  174  sage: out.find(version()) >= 0 
156  175  True 
… 
… 

175  194  sage: ret 
176  195  0 
177  196  
178   sage: (out, err, ret) = test_executable(["sage", "startuptime"]) 
179   sage: out.find("sage.all: ") >= 0 
180   True 
 197  Test ``sagerun`` on a Python file, both with an absolute and with a relative path:: 
 198  
 199  sage: import tempfile 
 200  sage: F = tempfile.NamedTemporaryFile(suffix=".py") 
 201  sage: F.write("print 3^33\n") 
 202  sage: F.flush() 
 203  sage: (out, err, ret) = test_executable(["sage", F.name]) 
 204  sage: print out 
 205  34 
181  206  sage: err 
182  207  '' 
183  208  sage: ret 
184  209  0 
185   
 210  sage: (dir,filename) = os.path.split(F.name) 
 211  sage: os.chdir(dir) 
 212  sage: (out, err, ret) = test_executable(["sage", filename]) 
 213  sage: print out 
 214  34 
 215  sage: err 
 216  '' 
 217  sage: ret 
 218  0 
 219  sage: del F # Close and delete the file 
 220  
 221  The same as above, but now with a ``.sage`` file. This indirectly 
 222  also tests the preparser:: 
 223  
 224  sage: import tempfile 
 225  sage: F = tempfile.NamedTemporaryFile(suffix=".sage") 
 226  sage: py_file = F.name[:5] + ".py" # Will be created by the preparser 
 227  sage: F.write("k.<a> = GF(5^3); print a^124\n") 
 228  sage: F.flush() 
 229  sage: (out, err, ret) = test_executable(["sage", F.name]) 
 230  sage: os.unlink(py_file) 
 231  sage: print out 
 232  1 
 233  sage: err 
 234  '' 
 235  sage: ret 
 236  0 
 237  sage: (dir,filename) = os.path.split(F.name) 
 238  sage: os.chdir(dir) 
 239  sage: (out, err, ret) = test_executable(["sage", filename]) 
 240  sage: os.unlink(py_file) 
 241  sage: print out 
 242  1 
 243  sage: err 
 244  '' 
 245  sage: ret 
 246  0 
 247  sage: del F # Close and delete the file 
 248  
186  249  Test external programs being called by Sage:: 
187  250  
188  251  sage: (out, err, ret) = test_executable(["sage", "sh"], "echo Hello World\nexit 42\n") 