-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f02fc18
commit 2a12055
Showing
11 changed files
with
199 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
#include "library/io_env.h" | ||
#include "util/path.h" | ||
|
||
namespace lean { | ||
struct io_env_ext : public environment_extension { | ||
std::string m_cwd; | ||
io_env_ext() : m_cwd(lgetcwd()) { } | ||
}; | ||
|
||
struct io_env_ext_reg { | ||
unsigned m_ext_id; | ||
io_env_ext_reg() { m_ext_id = environment::register_extension(std::make_shared<io_env_ext>()); } | ||
}; | ||
|
||
static io_env_ext_reg * g_ext = nullptr; | ||
static io_env_ext const & get_extension(environment const & env) { | ||
return static_cast<io_env_ext const &>(env.get_extension(g_ext->m_ext_id)); | ||
} | ||
|
||
static environment update(environment const & env, io_env_ext const & ext) { | ||
return env.update(g_ext->m_ext_id, std::make_shared<io_env_ext>(ext)); | ||
} | ||
|
||
environment set_cwd(environment const & env, std::string cwd) { | ||
auto ext = get_extension(env); | ||
ext.m_cwd = cwd; | ||
return update(env, ext); | ||
} | ||
|
||
std::string get_cwd(environment const & env) { | ||
auto & ext = get_extension(env); | ||
return ext.m_cwd; | ||
} | ||
|
||
void initialize_io_env() { | ||
g_ext = new io_env_ext_reg(); | ||
} | ||
|
||
void finalize_io_env() { | ||
delete g_ext; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
#include "kernel/environment.h" | ||
|
||
namespace lean { | ||
environment set_cwd(environment const & env, std::string cwd); | ||
std::string get_cwd(environment const & env); | ||
void initialize_io_env(); | ||
void finalize_io_env(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import system.io | ||
|
||
def this_dir := "tests/lean" | ||
|
||
meta def lean_root : tactic string := | ||
tactic.unsafe_run_io $ do | ||
dir ← io.env.get_cwd, | ||
return $ list.as_string $ dir.to_list.take (dir.length - this_dir.length - 1) | ||
|
||
open tactic | ||
|
||
meta def mk_def {α} [reflected α] [has_reflect α] (n : name) (tac : tactic α) : tactic unit := | ||
do let t := `(α), | ||
v ← tac, | ||
add_decl $ mk_definition n [] t (reflect v) | ||
|
||
run_cmd mk_def `root_dir lean_root | ||
|
||
meta def test' : tactic unit := (tactic.unsafe_run_io | ||
(do io.env.set_cwd "lean", | ||
io.env.get_cwd >>= io.put_str_ln) >> failed) | ||
|
||
run_cmd test' <|> trace "foo" | ||
|
||
def strip_prefix (p s : string) : string := | ||
list.as_string $ s.to_list.drop p.length | ||
|
||
meta def test : tactic unit := tactic.unsafe_run_io $ | ||
do io.env.get_cwd >>= io.put_str_ln ∘ strip_prefix root_dir, | ||
io.env.set_cwd "..", | ||
io.env.get_cwd >>= io.put_str_ln ∘ strip_prefix root_dir | ||
|
||
run_cmd (test >> test >> tactic.failed) <|> test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
foo | ||
/tests/lean | ||
/tests | ||
/tests | ||
|
||
/tests/lean | ||
/tests |