forked from runtimeverification/k
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseTestCase.java
More file actions
107 lines (85 loc) · 2.98 KB
/
BaseTestCase.java
File metadata and controls
107 lines (85 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) 2014-2019 K Team. All Rights Reserved.
package org.kframework.utils;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.name.Names;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.kframework.kdoc.KDocOptions;
import org.kframework.kil.Definition;
import org.kframework.kil.loader.Context;
import org.kframework.kompile.KompileOptions;
import org.kframework.krun.KRunOptions;
import org.kframework.krun.RunProcess;
import org.kframework.main.Main;
import org.kframework.utils.errorsystem.KExceptionManager;
import org.kframework.utils.file.FileUtil;
import org.kframework.utils.file.DefinitionDir;
import org.kframework.utils.file.KompiledDir;
import org.kframework.utils.inject.Concrete;
import org.kframework.utils.inject.DefinitionScope;
import org.kframework.utils.inject.SimpleScope;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.io.File;
@RunWith(MockitoJUnitRunner.class)
public abstract class BaseTestCase {
@Mock
protected Context context;
@Mock
protected Definition definition;
@Mock
protected KExceptionManager kem;
@Mock
protected Stopwatch sw;
@Mock
protected BinaryLoader loader;
@Mock
protected RunProcess rp;
@Mock
protected
File kompiledDir;
@Mock
File definitionDir;
@Mock
File tempDir;
@Mock
protected FileUtil files;
@Mock
protected DefinitionScope scope;
@Before
public void setUpWiring() {
context.kompileOptions = new KompileOptions();
}
public class DefinitionSpecificTestModule extends AbstractModule {
@Override
protected void configure() {
bind(KompileOptions.class).toInstance(context.kompileOptions);
bind(Definition.class).toInstance(definition);
bind(File.class).annotatedWith(KompiledDir.class).toInstance(kompiledDir);
bind(File.class).annotatedWith(DefinitionDir.class).toInstance(definitionDir);
bind(Definition.class).annotatedWith(Concrete.class).toInstance(definition);
}
@Provides
Context context() {
return context;
}
}
public class TestModule extends AbstractModule {
@Override
protected void configure() {
bind(RunProcess.class).toInstance(rp);
bind(KDocOptions.class).toInstance(new KDocOptions());
bind(KRunOptions.class).toInstance(new KRunOptions());
}
}
public void prepInjector(Injector injector, String tool, String[] args) {
SimpleScope scope = injector.getInstance(Key.get(SimpleScope.class, Names.named("requestScope")));
scope.enter();
DefinitionScope definitionScope = injector.getInstance(DefinitionScope.class);
definitionScope.enter(new File("."));
Main.seedInjector(scope, tool, args, new File("."), System.getenv());
}
}