Skip to content

Commit 75f3c7c

Browse files
baroquebobcatuujava
authored andcommitted
Mirah run mode should not stop the process unless compile failed
Before, we would exit zero when the main finished. If for example, you are running a swing app, that isn't so hot. Because, swing launches its own event thread (cherry picked from commit aeace8a)
1 parent 6442c43 commit 75f3c7c

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/org/mirah/mirah_command.mirah

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class MirahCommand
3636
def self.main(args:String[]):void
3737
list = Arrays.asList(args)
3838
if list.size > 0 && "run".equals(list.get(0))
39-
System.exit(run(list.subList(1, list.size)))
39+
result = run(list.subList(1, list.size))
40+
# NB only exit from a run if it failed.
41+
System.exit(result) unless result == 0
4042
elsif list.size > 0 && "compile".equals(list.get(0))
4143
System.exit(compile(list.subList(1, list.size)))
4244
else

src/org/mirah/tool/run_command.mirah

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class RunCommand < MirahTool
5858
main_method.invoke(nil, args)
5959
0
6060
else
61-
puts "No main method found"
61+
puts "Error: No main method found."
6262
1
6363
end
6464
end
@@ -78,7 +78,9 @@ class RunCommand < MirahTool
7878

7979
def self.main(args:String[]):void
8080
result = run(args)
81-
System.exit(result)
81+
82+
# NB only exit from a run if it failed.
83+
System.exit(result) unless result == 0
8284
end
8385

8486
def self.run(args: String[]): int

test/artifacts/jar_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ def test_happy_path
2020
out = `java -jar dist/mirahc.jar run -e 'puts 1'`
2121
assert_equal "1\n", out
2222
end
23+
24+
def test_run_doesnt_exit_early
25+
out = `java -jar dist/mirahc.jar run -e 'Thread.new {Thread.sleep(1); puts 1}.start'`
26+
assert_equal "1\n", out
27+
end
2328
end

0 commit comments

Comments
 (0)