Browse files

Use #!python to specify if an example must be run with the python pro…

…gram.

Not all of our examples will run successfully in CPython, as we will have some
code examples of how to use Ruby code from Python, and that will certainly dont
work on other Python implementations.

So now, every example explicitly specified which Python interpreters it must be
run with.
  • Loading branch information...
1 parent e5faf1a commit 1a72147bd3cf7deb03e892b1783c40f1ca8003ae @vic committed Jan 4, 2011
View
7 spec/examples/README.md
@@ -25,8 +25,11 @@ with two command line arguments, you should have the first line in the
Files not having that comment as first line will just be ignored.
Typhon is expected to be compatible as possible with the `python`
-program. Because of this all tests run with `typhon` will be also run
-with `python` and the output is expected to be equal.
+program. Because of this all tests run with `typhon` might also need
+to be run with `python` and the output is expected to be equal.
+
+ #! typhon examples/hello.py
+ #! python examples/hello.py
Also, some examples output memory locations like `0x0AF30` in that cases
.out files can use ruby regexes like: `#{/0x\w+/}`.
View
1 spec/examples/builtins.out
@@ -1,4 +1,5 @@
#! typhon examples/builtins.py
+#! python examples/builtins.py
__main__
wat
<type 'object'>
View
1 spec/examples/classes.out
@@ -1,2 +1,3 @@
#! typhon examples/classes.py
+#! python examples/classes.py
10
View
1 spec/examples/decorators.out
@@ -1,4 +1,5 @@
#! typhon examples/decorators.py
+#! python examples/decorators.py
1 2 3
<class '__main__.test'> 1 2 3
1 2 3
View
1 spec/examples/descriptors.out
@@ -1,4 +1,5 @@
#! typhon examples/descriptors.py
+#! python examples/descriptors.py
datadesc <__main__.DataDesc object at #{/0x\w+/}> None <class '__main__.test'>
desc <__main__.Desc object at #{/0x\w+/}> None <class '__main__.test'>
datadesc <__main__.DataDesc object at #{/0x\w+/}> <__main__.test object at #{/0x\w+/}> <class '__main__.test'>
View
1 spec/examples/embed_func.out
@@ -1,4 +1,5 @@
#! typhon examples/embed_func.py
+#! python examples/embed_func.py
zoom!
('floom', 'b')
boom
View
1 spec/examples/eval.out
@@ -1,2 +1,3 @@
#! typhon examples/eval.py
+#! python examples/eval.py
726
View
1 spec/examples/from_import.out
@@ -1,3 +1,4 @@
#! typhon examples/from_import.py
+#! python examples/from_import.py
imported
FOO
View
1 spec/examples/from_import_as.out
@@ -1,3 +1,4 @@
#! typhon examples/from_import_as.py
+#! python examples/from_import_as.py
imported
FOO
View
1 spec/examples/func.out
@@ -1,4 +1,5 @@
#! typhon examples/func.py
+#! python examples/func.py
---
hello Jack
wat: stuff
View
1 spec/examples/hello.out
@@ -1,2 +1,3 @@
#! typhon examples/hello.py
+#! python examples/hello.py
hello world
View
1 spec/examples/import.out
@@ -1,4 +1,5 @@
#! typhon examples/import.py
+#! python examples/import.py
imported
imported module
BAR
View
1 spec/examples/import_as.out
@@ -1,3 +1,4 @@
#! typhon examples/import_as.py
+#! python examples/import_as.py
imported
imported
View
1 spec/examples/literals.out
@@ -1 +1,2 @@
#! typhon examples/literals.py
+#! python examples/literals.py
View
1 spec/examples/numbers.out
@@ -1,4 +1,5 @@
#! typhon examples/numbers.py
+#! python examples/numbers.py
boom
<type 'int'> <type 'long'> <type 'int'>
11
View
1 spec/examples/pass.out
@@ -1,2 +1,3 @@
#! typhon examples/pass.py
+#! python examples/pass.py
None
View
1 spec/examples/singletons.out
@@ -1,4 +1,5 @@
#! typhon examples/singletons.py
+#! python examples/singletons.py
None
<type 'NoneType'>
NotImplemented
View
43 spec/examples_spec.rb
@@ -1,14 +1,18 @@
require 'open3'
+require 'strscan'
base = File.expand_path("..", File.dirname(__FILE__))
Dir.glob(File.expand_path("**/*.out", File.dirname(__FILE__))) do |file|
- content = File.read file
- m = /#!\s*typhon\s+(.*)$/.match(content)
- next unless m
- cmd = m[1]
- content = content.sub(/.*?\n/, '')
+ scanner = StringScanner.new(File.read file)
+ runner_re = /^#!\s*(typhon|python)\s+(.*)(\n|\r\n)/
+ runners = {}
+
+ runners[scanner[1]] = scanner[2] while scanner.scan runner_re
+ next if runners.empty?
+
+ content = scanner.rest
# Allow regexp literals inside the file content so we can match
# things like memory addresses or anything that can vary
@@ -19,26 +23,17 @@
expect = Regexp.new(Object.new.instance_eval content)
- describe "Example output of `typhon #{cmd}`" do
- it "should match content of #{file}" do
- stdio = nil
- Dir.chdir base do
- stdio = Open3.popen3("./bin/typhon #{cmd}")
+ runners.each do |program, cmd|
+ describe "Output of `#{program} #{cmd}`" do
+ it "should match content of #{file}" do
+ stdio = nil
+ program = "./bin/typhon" if program == "typhon"
+ Dir.chdir base do
+ stdio = Open3.popen3("#{program} #{cmd}")
+ end
+ output = stdio[1].read
+ output.should =~ expect
end
- output = stdio[1].read
- output.should =~ expect
end
end
-
- describe "Example output of `python #{cmd}`" do
- it "should match content of #{file}" do
- stdio = nil
- Dir.chdir base do
- stdio = Open3.popen3("python #{cmd}")
- end
- output = stdio[1].read
- output.should =~ expect
- end
- end
-
end

0 comments on commit 1a72147

Please sign in to comment.