]> git.lizzy.rs Git - metalua.git/commitdiff
fix portability on tests/tun.mlua
authorFabien <metalua@gmail.com>
Sat, 26 Nov 2011 14:44:10 +0000 (15:44 +0100)
committerFabien <metalua@gmail.com>
Sat, 26 Nov 2011 14:44:10 +0000 (15:44 +0100)
src/tests/run.mlua

index dd2f3a28097b584b09de943f2847e73d8ab1dafa..b452056dc5ffb4b3bcd84a4ef91bd12c5beb39a7 100644 (file)
@@ -3,12 +3,23 @@
 
 -{ extension 'xloop' }
 
-ls = io.popen ( (os.getenv("OS") or "") :match "^Windows" and "dir /b" or "ls")
+LS_COMMANDS = { "ls", "dir /b" } 
+for i, cmd in ipairs(LS_COMMANDS) do
+   local f = io.popen (cmd)
+   ls = f :read '*a'
+   f :close()
+   if ls ~= '' then
+      break
+   elseif i == #LS_COMMANDS then
+      error "Can't figure out how to list files on your OS"
+   end
+end
+
 this_script = arg[1]
 
 local errors = {}
 
-for filename in ls :lines() if filename ~= this_script and filename :strmatch  "%.m?lua$" do
+for filename in ls :gmatch "[^\n]+" if filename ~= this_script and filename :strmatch  "%.m?lua$" do
    printf ("*** running %s ***", filename)
    local ret = os.execute ("metalua "..filename)
    if ret ~= 0 then 
@@ -16,8 +27,6 @@ for filename in ls :lines() if filename ~= this_script and filename :strmatch  "
    end
 end
 
-ls :close()
-
 if #errors > 0 then
    print("\n\n================================================================================") 
    error(