Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F114411
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/Makefile b/Makefile
index cb2e93d..cbd6fec 100644
--- a/Makefile
+++ b/Makefile
@@ -1,29 +1,21 @@
# Apprentice binary
ERL_EI_INCLUDE:=$(shell erl -eval 'io:format("~s", [code:lib_dir(erl_interface, include)])' -s init stop -noshell | head -1)
ERL_EI_LIB:=$(shell erl -eval 'io:format("~s", [code:lib_dir(erl_interface, lib)])' -s init stop -noshell | head -1)
CFLAGS = -std=c99 -g -Wall -Werror
CPPFLAGS = -I$(ERL_EI_INCLUDE)
LDFLAGS = -L$(ERL_EI_LIB)
LDLIBS = -lpthread -lei -lm -lmagic
-BEAM_FILES = _build/
PRIV = priv/
RM = rm -Rf
-# Unit test custom magic file
-
-MAGIC = file
-
-all: priv/apprentice test/elixir.mgc
-
-test/%.mgc: test/%
- cd test; file -C -m ../$^
+all: priv/apprentice
priv/apprentice: src/apprentice.c
mkdir -p priv
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
clean:
- $(RM) $(PRIV) $(BEAM_FILES) test/*.mgc
+ $(RM) $(PRIV)
.PHONY: clean
diff --git a/test/gen_magic/gen_magic_test.exs b/test/gen_magic/gen_magic_test.exs
index dbd287c..9699177 100644
--- a/test/gen_magic/gen_magic_test.exs
+++ b/test/gen_magic/gen_magic_test.exs
@@ -1,53 +1,55 @@
defmodule GenMagicTest do
use GenMagic.MagicCase
alias GenMagic.Result
doctest GenMagic
@iterations 100
test "Makefile is text file" do
{:ok, pid} = GenMagic.Server.start_link([])
path = absolute_path("Makefile")
assert {:ok, %{mime_type: "text/x-makefile"}} = GenMagic.Server.perform(pid, path)
end
@tag external: true
test "Load test local files" do
{:ok, pid} = GenMagic.Server.start_link([])
files_stream()
|> Stream.cycle()
|> Stream.take(@iterations)
|> Stream.map(&assert {:ok, %Result{}} = GenMagic.Server.perform(pid, &1))
|> Enum.all?()
|> assert
end
test "Non-existent file" do
Process.flag(:trap_exit, true)
{:ok, pid} = GenMagic.Server.start_link([])
path = missing_filename()
assert_no_file(GenMagic.Server.perform(pid, path))
end
test "Named process" do
{:ok, pid} = GenMagic.Server.start_link(name: :gen_magic)
path = absolute_path("Makefile")
assert {:ok, %{cycles: 0}} = GenMagic.Server.status(:gen_magic)
assert {:ok, %{cycles: 0}} = GenMagic.Server.status(pid)
assert {:ok, %Result{} = result} = GenMagic.Server.perform(:gen_magic, path)
assert {:ok, %{cycles: 1}} = GenMagic.Server.status(:gen_magic)
assert {:ok, %{cycles: 1}} = GenMagic.Server.status(pid)
assert "text/x-makefile" = result.mime_type
end
test "Custom database file recognises Elixir files" do
- database = absolute_path("test/elixir.mgc")
+ database = absolute_path("elixir.mgc")
+ on_exit(fn() -> File.rm(database) end)
+ {_, 0} = System.cmd("file", ["-C", "-m", absolute_path("test/elixir")])
{:ok, pid} = GenMagic.Server.start_link(database_patterns: [database])
path = absolute_path("mix.exs")
assert {:ok, %Result{} = result} = GenMagic.Server.perform(pid, path)
assert "text/x-elixir" = result.mime_type
assert "us-ascii" = result.encoding
assert "Elixir module source text" = result.content
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Nov 26, 6:40 AM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40226
Default Alt Text
(3 KB)
Attached To
Mode
R20 majic
Attached
Detach File
Event Timeline
Log In to Comment